<?php

namespace Koneko\SatCatalogs\Models;

use Illuminate\Database\Eloquent\Model;

class Colonia extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'sat_colonia';


    /**
     * The attributes that are mass assignable.
     *
     * @var string[]
     */
    protected $fillable = [
        'c_colonia',
        'c_codigo_postal',
        'nombre_del_asentamiento',
    ];


    public static function selectList($c_codigo_postal, $c_colonia = false)
    {
        return self::select('c_colonia', 'nombre_del_asentamiento')
            ->where('c_codigo_postal', $c_codigo_postal)
            ->when($c_colonia, function ($query) use ($c_colonia) {
                $query->where('c_colonia', $c_colonia);
            })
            ->orderBy('nombre_del_asentamiento')
            ->pluck('nombre_del_asentamiento', 'c_colonia');
    }
}
