<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;

class FranchiseAddress extends Model
{
    protected $table = 'franchise_addresses';

    public $incrementing = false;
    protected $keyType = 'string';

    protected $fillable = [
        'id',
        'zoho_franchise_id',
        'status',
        'territory_country',
        'territory_state',
        'territory_city',
        'postal_code',
        'address',
        'latitude',
        'longitude',
    ];

    protected $casts = [
        'latitude' => 'decimal:7',
        'longitude' => 'decimal:7',
    ];

    protected static function booted(): void
    {
        static::creating(function (self $model) {
            if (empty($model->id)) {
                $model->id = (string) Str::uuid();
            }
        });
    }

    public function franchisee()
    {
        return $this->belongsTo(Franchisee::class, 'zoho_franchise_id', 'zoho_franchise_id');
    }
}
