<?php

namespace App\Models;

use App\Enums\ChargeBasis;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class BookingItem extends Model
{
    /**
     * @var list<string>
     */
    protected $fillable = [
        'booking_id',
        'package_id',
        'product_id',
        'booking_space_id',
        'description',
        'quantity',
        'unit_price',
        'charge_basis',
        'guest_count',
        'billable_days',
        'billable_hours',
        'discount_amount',
        'tax_rate',
        'tax_amount',
        'line_total',
        'sort_order',
        'is_complimentary',
    ];

    /**
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            'booking_id' => 'integer',
            'package_id' => 'integer',
            'product_id' => 'integer',
            'booking_space_id' => 'integer',
            'quantity' => 'decimal:2',
            'unit_price' => 'decimal:2',
            'charge_basis' => ChargeBasis::class,
            'guest_count' => 'integer',
            'billable_days' => 'integer',
            'billable_hours' => 'integer',
            'discount_amount' => 'decimal:2',
            'tax_rate' => 'decimal:2',
            'tax_amount' => 'decimal:2',
            'line_total' => 'decimal:2',
            'sort_order' => 'integer',
            'is_complimentary' => 'boolean',
        ];
    }

    /**
     * @return BelongsTo<Booking, $this>
     */
    public function booking(): BelongsTo
    {
        return $this->belongsTo(Booking::class);
    }

    /**
     * @return BelongsTo<Package, $this>
     */
    public function package(): BelongsTo
    {
        return $this->belongsTo(Package::class);
    }

    /**
     * @return BelongsTo<Product, $this>
     */
    public function product(): BelongsTo
    {
        return $this->belongsTo(Product::class);
    }

    /**
     * @return BelongsTo<BookingSpace, $this>
     */
    public function bookingSpace(): BelongsTo
    {
        return $this->belongsTo(BookingSpace::class);
    }
}
