<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;

class Branch extends Model
{
    use HasFactory, SoftDeletes;

    protected $fillable = [
        'name',
        'code',
        'address',
        'city',
        'state',
        'country',
        'pincode',
        'phone',
        'email',
        'opening_time',
        'closing_time',
        'status',
        'manager_id',
        'notes',
    ];

    protected function casts(): array
    {
        return [
            'opening_time' => 'datetime:H:i',
            'closing_time' => 'datetime:H:i',
        ];
    }

    public function manager(): BelongsTo
    {
        return $this->belongsTo(User::class, 'manager_id');
    }

    public function users(): HasMany
    {
        return $this->hasMany(User::class, 'branch_id');
    }

    public function customers(): HasMany
    {
        return $this->hasMany(Customer::class, 'branch_id');
    }

    public function staffProfiles(): HasMany
    {
        return $this->hasMany(StaffProfile::class, 'branch_id');
    }

    public function appointments(): HasMany
    {
        return $this->hasMany(Appointment::class, 'branch_id');
    }

    public function walkInQueues(): HasMany
    {
        return $this->hasMany(WalkInQueue::class, 'branch_id');
    }
}
