<?php

namespace App\Models;

use App\Models\Concerns\Auditable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;

class Branch extends Model
{
    use Auditable, SoftDeletes;

    protected $fillable = [
        'organization_id', 'parent_id', 'code', 'name', 'type', 'province', 'municipality',
        'address', 'phone', 'email', 'timezone', 'is_headquarters', 'is_active',
    ];

    protected function casts(): array
    {
        return ['is_headquarters' => 'boolean', 'is_active' => 'boolean'];
    }

    public function organization(): BelongsTo
    {
        return $this->belongsTo(Organization::class);
    }

    public function parent(): BelongsTo
    {
        return $this->belongsTo(self::class, 'parent_id');
    }
}
