<?php

namespace App\Models\CRM;

use App\Enums\AddressType;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class Address extends Model
{
    /** @use HasFactory<\Database\Factories\CRM\AddressFactory> */
    use HasFactory;

    protected $fillable = [
        'line_1',
        'type',
        'city_id',
        'addressable_type',
        'addressable_id',
        'status',
    ];

    protected $casts = [
        'type' => AddressType::class, // Laravel will cast this to/from the enum
    ];

    public function city()
    {
        return $this->belongsTo(City::class);
    }

    public function addressable()
    {
        return $this->morphTo();
    }

    public function scopeActive($query)
    {
        return $query->where('status', 'active');
    }

}
