<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Address extends Model
{
    use HasFactory, SoftDeletes;

    protected $fillable = [
        'source',
        'source_id',
        'zip_code',
        'address',
        'number',
        'district',
        'has_complement',
        'complement',
        'nickname',
        'instructions',
        'city_id',
        'state_id',
        'address_type',
        'is_primary',
        'latitude',
        'longitude',
    ];

    protected $casts = [
        'has_complement' => 'boolean',
        'is_primary' => 'boolean',
        'latitude' => 'float',
        'longitude' => 'float',
        'created_at' => 'datetime',
        'updated_at' => 'datetime',
        'deleted_at' => 'datetime',
    ];

    public function city()
    {
        return $this->belongsTo(City::class)->select('id', 'name');
    }

    public function state()
    {
        return $this->belongsTo(State::class)->select('id', 'name', 'code');
    }
}
