<?php

namespace Modules\Bms\Entities;

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

class BmsBooking extends Model
{
    protected $table = 'bms_bookings';

    protected $fillable = [
        'business_id', 'booking_no', 'contact_id', 'lead_id', 'location_id',
        'status', 'event_type', 'event_date', 'start_time', 'end_time',
        'attendees', 'total_amount', 'discount_amount', 'deposit_amount',
        'erp_invoice_id', 'notes', 'created_by', 'confirmed_at',
        'cancelled_at', 'cancelled_by', 'cancellation_reason', 'cancellation_reason_code', 'penalty_percent',
        'penalty_amount', 'refund_amount', 'rescheduled_from', 'reschedule_count',
        'contracted_at', 'completed_at',
    ];

    protected $casts = [
        'event_date'      => 'date',
        'attendees'       => 'integer',
        'total_amount'    => 'decimal:2',
        'discount_amount' => 'decimal:2',
        'deposit_amount'  => 'decimal:2',
        'penalty_percent' => 'decimal:3',
        'penalty_amount'  => 'decimal:2',
        'refund_amount'   => 'decimal:2',
        'rescheduled_from' => 'date',
        'reschedule_count' => 'integer',
        'confirmed_at'    => 'datetime',
        'cancelled_at'    => 'datetime',
        'contracted_at'   => 'datetime',
        'completed_at'    => 'datetime',
    ];

    public function contact(): BelongsTo
    {
        return $this->belongsTo(\App\Contact::class, 'contact_id');
    }

    public function lead(): BelongsTo
    {
        return $this->belongsTo(BmsLead::class, 'lead_id');
    }

    public function halls(): HasMany
    {
        return $this->hasMany(BmsBookingHall::class, 'booking_id');
    }

    public function paymentSchedules(): HasMany
    {
        return $this->hasMany(BmsPaymentSchedule::class, 'booking_id');
    }

    public function events(): HasMany
    {
        return $this->hasMany(BmsBookingEvent::class, 'booking_id');
    }
}
