<?php

namespace App\Models;

use App\Traits\GeneratesReference;
use Illuminate\Database\Eloquent\Model;

class Booking extends Model
{
    use GeneratesReference;

    protected $fillable = [
        'reference',
        'guest_id',
        'created_by',
        'updated_by',
        'source',
        'check_in',
        'check_out',
        'total_price',
        'base_currency',
        'display_total_price',
        'display_currency',
        'exchange_rate',
        'currency_rate_id',
        'price_data',
        'payment_option',
        'status',
        'booked_at',
        'cancelled_at',
        'checked_in_at',
        'checked_out_at',
        'addons',
        'addon_total',
        'note'
    ];

    protected $casts = [
        'price_data' => 'array',
        'addons' => 'array',
        'booked_at' => 'datetime',
        'cancelled_at' => 'datetime',
        'checked_in_at' => 'datetime',
        'checked_out_at' => 'datetime',
    ];

    protected $reference_prefix = 'BKG';

    public function guest()
    {
        return $this->belongsTo(Guest::class);
    }

    public function rooms()
    {
        return $this->hasMany(BookingRoom::class);
    }

    public function getRouteKeyName()
    {
        return 'reference';
    }
}
