<?php

namespace App\Models;

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

class Branch extends Model
{
    use HasFactory;

    protected $table = 'branches';

    protected $fillable = [
        'name',
        'code',
        'restaurant_code',
        'logo',
        'phone',
        'address',
        'status',
        'restaurant_id',
        'opening_time',
        'closing_time',
    ];

    public function restaurant()
    {
        return $this->belongsTo(Restaurant::class, 'restaurant_id');
    }

    public function agents()
    {
        return $this->hasMany(Agent::class, 'branch_id');
    }

    public function stockOuts()
    {
        return $this->hasMany(StockOut::class, 'branch_id');
    }

    public function stockClosings()
    {
        return $this->hasMany(StockClosing::class, 'branch_id');
    }

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

    public function waiters()
    {
        return $this->hasMany(Waiter::class, 'branch_id');
    }

    public function tables()
    {
        return $this->hasMany(PosTable::class, 'branch_id');
    }

    public function menuItems()
    {
        return $this->hasMany(PosMenuItem::class, 'branch_id');
    }

    public function orders()
    {
        return $this->hasMany(PosOrder::class, 'branch_id');
    }

    public function menuCategories()
    {
        return $this->hasMany(RestaurantMenuCategory::class, 'branch_id');
    }

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

    public function shifts()
    {
        return $this->hasMany(Shift::class, 'branch_id');
    }

    public function dailyExpenses()
    {
        return $this->hasMany(DailyExpense::class, 'branch_id');
    }

    public function isActive()
    {
        return $this->status === 'active';
    }
}
