<?php

namespace App\Models\Supplier;

use App\Models\User;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class SupplierHotelFactSheet extends Model
{
    use HasFactory;

    protected $table = 'supplier_hotel_fact_sheets';

    protected $fillable = [
        'supplier_id',
        'star_rating',
        'total_rooms',
        'total_area',
        'concept',
        'check_in_time',
        'check_out_time',
        'distance_to_airport',
        'distance_to_center',
        'distance_to_beach',
        'description',
        'general_features',
        'room_types',
        'pools',
        'meeting_rooms',
        'food_beverages',
        'created_by',
        'updated_by',
    ];

    protected function casts(): array
    {
        return [
            'general_features' => 'array',
            'room_types' => 'array',
            'pools' => 'array',
            'meeting_rooms' => 'array',
            'food_beverages' => 'array',
        ];
    }

    public function supplier()
    {
        return $this->belongsTo(Supplier::class);
    }

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

    public function updater()
    {
        return $this->belongsTo(User::class, 'updated_by');
    }

    protected static function boot(): void
    {
        parent::boot();

        static::creating(function (SupplierHotelFactSheet $sheet) {
            if (auth()->check()) {
                $sheet->created_by = auth()->id();
            }
        });

        static::updating(function (SupplierHotelFactSheet $sheet) {
            if (auth()->check()) {
                $sheet->updated_by = auth()->id();
            }
        });
    }
}
