<?php

namespace Modules\Admin\App\Models;

use Modules\Admin\App\Models\Sat\CodigoPostal;
use Modules\Admin\App\Models\Sat\Colonia;
use Modules\Admin\App\Models\Sat\Estado;
use Modules\Admin\App\Models\Sat\Municipio;
use Illuminate\Database\Eloquent\Model;

class ContactableAddress extends Model
{
    protected $table = 'contactable_addresses';

    protected $fillable = [
        'contactable_id',
        'contactable_type',
        'type',
        'c_estado',
        'c_municipio',
        'c_codigo_postal',
        'c_colonia',
        'direccion',
        'num_ext',
        'num_int',
        'referencia',
        'lat',
        'lng',
        'preference_level',
    ];

    /**
     * Casts for the model attributes.
     */
    protected $casts = [
        'lat' => 'float',
        'lng' => 'float',
        'preference_level' => 'integer',
    ];

    /**
     * Polymorphic relationship to the parent model.
     */
    public function contactable()
    {
        return $this->morphTo();
    }

    /**
     * Relationships to SAT tables.
     */
    public function estado()
    {
        return $this->belongsTo(Estado::class, 'c_estado', 'c_estado');
    }

    public function municipio()
    {
        return $this->belongsTo(Municipio::class, 'c_municipio', 'c_municipio');
    }

    public function codigoPostal()
    {
        return $this->belongsTo(CodigoPostal::class, 'c_codigo_postal', 'c_codigo_postal');
    }

    public function colonia()
    {
        return $this->belongsTo(Colonia::class, 'c_colonia', 'c_colonia');
    }
}
