<?php

use App\Models\WorkingHour;

test('getDayName returns correct English day names', function () {
    expect(WorkingHour::getDayName(0, 'en'))->toBe('Sunday');
    expect(WorkingHour::getDayName(1, 'en'))->toBe('Monday');
    expect(WorkingHour::getDayName(2, 'en'))->toBe('Tuesday');
    expect(WorkingHour::getDayName(3, 'en'))->toBe('Wednesday');
    expect(WorkingHour::getDayName(4, 'en'))->toBe('Thursday');
    expect(WorkingHour::getDayName(5, 'en'))->toBe('Friday');
    expect(WorkingHour::getDayName(6, 'en'))->toBe('Saturday');
});

test('getDayName returns correct Arabic day names', function () {
    expect(WorkingHour::getDayName(0, 'ar'))->toBe('الأحد');
    expect(WorkingHour::getDayName(1, 'ar'))->toBe('الإثنين');
    expect(WorkingHour::getDayName(2, 'ar'))->toBe('الثلاثاء');
    expect(WorkingHour::getDayName(3, 'ar'))->toBe('الأربعاء');
    expect(WorkingHour::getDayName(4, 'ar'))->toBe('الخميس');
    expect(WorkingHour::getDayName(5, 'ar'))->toBe('الجمعة');
    expect(WorkingHour::getDayName(6, 'ar'))->toBe('السبت');
});

test('getDayName defaults to English for unsupported locale', function () {
    expect(WorkingHour::getDayName(0, 'fr'))->toBe('Sunday');
});

test('getSlots returns correct 1-hour slots', function () {
    $workingHour = WorkingHour::factory()->create([
        'day_of_week' => 1,
        'start_time' => '09:00:00',
        'end_time' => '12:00:00',
        'is_active' => true,
    ]);

    $slots = $workingHour->getSlots(60);

    expect($slots)->toBe(['09:00', '10:00', '11:00']);
});

test('getSlots returns correct 30-minute slots', function () {
    $workingHour = WorkingHour::factory()->create([
        'day_of_week' => 1,
        'start_time' => '09:00:00',
        'end_time' => '11:00:00',
        'is_active' => true,
    ]);

    $slots = $workingHour->getSlots(30);

    expect($slots)->toBe(['09:00', '09:30', '10:00', '10:30']);
});

test('getSlots returns empty array when duration exceeds available time', function () {
    $workingHour = WorkingHour::factory()->create([
        'day_of_week' => 1,
        'start_time' => '09:00:00',
        'end_time' => '09:30:00',
        'is_active' => true,
    ]);

    expect($workingHour->getSlots(60))->toBe([]);
});

test('getSlots returns empty array when start and end times are equal', function () {
    $workingHour = WorkingHour::factory()->create([
        'day_of_week' => 1,
        'start_time' => '09:00:00',
        'end_time' => '09:00:00',
        'is_active' => true,
    ]);

    expect($workingHour->getSlots(60))->toBe([]);
});

test('active scope returns only active working hours', function () {
    WorkingHour::factory()->create([
        'day_of_week' => 0,
        'is_active' => true,
    ]);
    WorkingHour::factory()->create([
        'day_of_week' => 1,
        'is_active' => false,
    ]);
    WorkingHour::factory()->create([
        'day_of_week' => 2,
        'is_active' => true,
    ]);

    expect(WorkingHour::active()->count())->toBe(2);
});

test('day_of_week is cast to integer', function () {
    $workingHour = WorkingHour::factory()->create([
        'day_of_week' => 3,
    ]);

    expect($workingHour->day_of_week)->toBeInt();
});

test('is_active is cast to boolean', function () {
    $workingHour = WorkingHour::factory()->create([
        'is_active' => 1,
    ]);

    expect($workingHour->is_active)->toBeBool()
        ->and($workingHour->is_active)->toBeTrue();
});
