<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class RoomCategory extends Model
{
    protected $fillable = [
        'short_name',
        'name',
        'slug',
        'sort_order',
        'description',

        'details',
        'policies',

        'base_price',

        'max_adults',
        'max_children',
        'default_bed_count',
        'default_bathroom_count',
        'default_size',

        'is_published',
    ];


    protected $casts = [
        'is_published' => 'boolean',
        'base_price' => 'decimal:2',
    ];


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

    public function facilities()
    {
        return $this->belongsToMany(Facility::class);
    }

    public function mealPackages()
    {
        return $this->belongsToMany(MealPackage::class);
    }

    public function addOns()
    {
        return $this->belongsToMany(Addon::class)->with('variants');
    }

    public function priceModifiers()
    {
        return $this->belongsToMany(PriceModifier::class, 'modifier_category', 'category_id', 'modifier_id');
    }

    public static function getMaxAdultsAllowed()
    {
        return self::max('max_adults') ?? 1;
    }

    public static function getMaxChildrenAllowed()
    {
        return self::max('max_children') ?? 0;
    }
}
