<?php

declare(strict_types=1);

namespace App\Models;

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

class Transaction extends Model
{
    protected $fillable = [
        'transaction_number',
        'outlet_id',
        'user_id',
        'total_amount',
        'tax_amount',
        'service_charge_amount',
        'payment_method',
        'status',
        'order_type',
        'table_id',
        'customer_id',
        'queue_number',
        'discount_amount',
        'points_redeemed',
        'waiter_id',
        'courier_id',
        'delivery_status',
    ];

    protected $casts = [
        'total_amount' => 'decimal:2',
        'tax_amount' => 'decimal:2',
        'service_charge_amount' => 'decimal:2',
        'discount_amount' => 'decimal:2',
        'points_redeemed' => 'integer',
    ];

    /**
     * Get the outlet where the transaction occurred.
     */
    public function outlet(): BelongsTo
    {
        return $this->belongsTo(Outlet::class);
    }

    /**
     * Get the cashier (user) who took the transaction.
     */
    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class);
    }

    /**
     * Get the items in this transaction.
     */
    public function items(): HasMany
    {
        return $this->hasMany(TransactionItem::class);
    }

    /**
     * Get the dining table associated.
     */
    public function table(): BelongsTo
    {
        return $this->belongsTo(Table::class);
    }

    /**
     * Get the customer associated.
     */
    public function customer(): BelongsTo
    {
        return $this->belongsTo(Customer::class);
    }

    /**
     * Get the waiter associated.
     */
    public function waiter(): BelongsTo
    {
        return $this->belongsTo(User::class, 'waiter_id');
    }

    /**
     * Get the courier associated.
     */
    public function courier(): BelongsTo
    {
        return $this->belongsTo(Courier::class);
    }
}
