<?php

namespace App\Models\Room;

use App\Models\Crm\Customer;
use App\Models\Crm\Contract;
use App\Models\User;
use App\Traits\BelongsToStore;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Reservation extends Model
{
    use BelongsToStore;

    protected $fillable = [
        'store_id', 'customer_id', 'contract_id', 'room_id',
        'check_in_date', 'check_out_date',
        'actual_check_in', 'actual_check_out',
        'status', 'remark', 'created_by',
    ];

    protected function casts(): array
    {
        return [
            'check_in_date' => 'date',
            'check_out_date' => 'date',
            'actual_check_in' => 'datetime',
            'actual_check_out' => 'datetime',
            'status' => 'integer',
        ];
    }

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

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

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

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

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