<?php
declare(strict_types=1);

namespace App\Modules\SportsActivity\Models;

use App\Core\Model;

class FacilityUnit extends Model
{
    protected static string $table = 'sa_facility_units';
    protected static string $primaryKey = 'id';
    protected static bool $timestamps = true;
    protected static bool $softDelete = false;
    protected static bool $dispatchEvents = false;
    protected static bool $autoTrackAuthor = true;

    protected static array $fillable = [
        'facility_id', 'code', 'name_ar', 'name_en', 'unit_type',
        'booking_mode', 'max_capacity', 'sort_order', 'dimensions_json',
        'config_json', 'is_active',
    ];

    public static function getUnitTypeOptions(): array
    {
        return [
            'lane'  => 'حارة',
            'court' => 'كورت',
            'pitch' => 'ملعب',
            'ring'  => 'حلبة',
            'mat'   => 'بساط',
            'room'  => 'غرفة',
        ];
    }

    public static function getBookingModeOptions(): array
    {
        return [
            'exclusive' => 'حصري (حجز كامل)',
            'shared'    => 'مشترك (سعة متعددة)',
        ];
    }

    public function isShared(): bool
    {
        return $this->booking_mode === 'shared';
    }

    public function isExclusive(): bool
    {
        return $this->booking_mode === 'exclusive';
    }

    public static function getByFacility(int $facilityId): array
    {
        return static::query()
            ->where('facility_id', '=', $facilityId)
            ->where('is_active', '=', 1)
            ->orderBy('sort_order', 'ASC')
            ->get();
    }
}
