<?php

use App\Models\Service;
use App\Models\User;
use Carbon\Carbon;

test('home route redirects unauthenticated users to login', function () {
    $response = $this->get('/');

    $response->assertRedirect('/login');
});

test('home route redirects authenticated users to next upcoming service edit page', function () {
    Carbon::setTestNow('2026-06-01 10:00:00');

    $user = User::factory()->create();
    $service = Service::factory()->create(['date' => now()->addWeek()]);

    $response = $this->actingAs($user)->get('/');

    $response->assertRedirect(route('services.edit', $service->id));
});

test('home route redirects authenticated users to services index when no upcoming service exists', function () {
    Carbon::setTestNow('2026-06-01 10:00:00');

    $user = User::factory()->create();

    $response = $this->actingAs($user)->get('/');

    $response->assertRedirect(route('services.index'));
});
