<?php

namespace Tests\Feature;

use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class BackupRestoreTest extends TestCase
{
    use RefreshDatabase;

    /**
     * Guest users cannot access the backup manager.
     */
    public function test_guests_are_redirected_from_backup_manager()
    {
        $response = $this->get('/admin/backup-manager');

        // Filament auth middleware will redirect to admin login
        $response->assertRedirect('/admin/login');
    }

    /**
     * Non-admin users (e.g. customers) cannot access the backup manager.
     */
    public function test_customers_cannot_access_backup_manager()
    {
        $customer = User::factory()->create([
            'role' => 'customer',
        ]);

        $response = $this->actingAs($customer)->get('/admin/backup-manager');

        // Since they cannot access the panel, they get 403 or redirect
        $response->assertStatus(403);
    }

    /**
     * Admin users can access the backup manager page successfully.
     */
    public function test_admins_can_access_backup_manager()
    {
        $admin = User::factory()->create([
            'role' => 'admin',
        ]);

        $response = $this->actingAs($admin)->get('/admin/backup-manager');

        $response->assertStatus(200);
        $response->assertSee('System Backups');
        $response->assertSee('Automated Backup Schedules');
        $response->assertSee('Retention Policy');
    }
}
