<?php
declare(strict_types=1);

namespace App\Modules\SportsActivity\Models;

use App\Core\Model;

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

    protected static array $fillable = [
        'booking_number', 'facility_unit_id', 'booking_type', 'booking_date',
        'start_time', 'end_time', 'group_id', 'coach_id', 'booker_type',
        'booker_id', 'booker_name', 'participant_count', 'spots_reserved',
        'total_amount', 'payment_status', 'status', 'is_recurring',
        'recurrence_pattern_json', 'parent_booking_id', 'cancellation_reason',
        'cancelled_by', 'cancelled_at', 'notes', 'branch_id',
    ];

    public static function getBookingTypeOptions(): array
    {
        return [
            'hourly' => 'حجز بالساعة',
            'training' => 'تدريب',
            'maintenance' => 'صيانة',
            'blocked' => 'محجوز',
        ];
    }

    public static function getStatusOptions(): array
    {
        return [
            'pending' => 'في الانتظار',
            'confirmed' => 'مؤكد',
            'checked_in' => 'تم الحضور',
            'completed' => 'مكتمل',
            'cancelled' => 'ملغي',
            'no_show' => 'لم يحضر',
        ];
    }

    public static function getPaymentStatusOptions(): array
    {
        return [
            'unpaid' => 'غير مدفوع',
            'paid' => 'مدفوع',
            'partial' => 'مدفوع جزئياً',
            'refunded' => 'مسترد',
        ];
    }

    public static function generateNumber(): string
    {
        return 'BK-' . date('Ymd') . '-' . str_pad((string)random_int(1, 9999), 4, '0', STR_PAD_LEFT);
    }
}
