<?php

namespace App\Models;

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

#[Fillable([
    'branch_id', 'table_id', 'waiter_id', 'biller_id',
    'order_type', 'status', 'subtotal', 'gst_amount',
    'discount_type', 'discount_value', 'discount_amount',
    'grand_total', 'payment_method',
    'split_cash', 'split_card', 'split_upi',
    'customer_name', 'customer_phone', 'delivery_address',
])]
class Order extends Model
{
    protected $casts = [
        'subtotal' => 'decimal:2',
        'gst_amount' => 'decimal:2',
        'discount_value' => 'decimal:2',
        'discount_amount' => 'decimal:2',
        'grand_total' => 'decimal:2',
        'split_cash' => 'decimal:2',
        'split_card' => 'decimal:2',
        'split_upi' => 'decimal:2',
    ];

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

    public function table(): BelongsTo
    {
        return $this->belongsTo(RestaurantTable::class, 'table_id');
    }

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

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

    public function items(): HasMany
    {
        return $this->hasMany(OrderItem::class);
    }

    public function kots(): HasMany
    {
        return $this->hasMany(Kot::class);
    }
}
