<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

#[Fillable(['branch_id', 'area_id', 'name', 'capacity', 'status', 'is_active', 'pos_x', 'pos_y', 'width', 'height', 'shape'])]
class RestaurantTable extends Model
{
    public function branch(): BelongsTo
    {
        return $this->belongsTo(Branch::class);
    }

    public function area(): BelongsTo
    {
        return $this->belongsTo(TableArea::class, 'area_id');
    }

    public function activeOrder()
    {
        return $this->hasOne(Order::class, 'table_id')->where('status', 'active');
    }

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

    /**
     * Scope a query to only include tables of a specific branch.
     */
    public function scopeForBranch($query, $branchId)
    {
        return $query->where('branch_id', $branchId);
    }
}
