<?php

namespace Tests\Feature;

use Tests\TestCase;

class ProductionReadinessCheckTest extends TestCase
{
    public function test_unsafe_production_configuration_fails_fast(): void
    {
        config([
            'app.env' => 'local',
            'app.key' => '',
            'app.debug' => true,
            'app.url' => 'http://microfinance.test',
            'database.default' => 'sqlite',
            'queue.default' => 'sync',
            'session.encrypt' => false,
            'session.secure' => false,
            'session.http_only' => false,
            'session.same_site' => 'lax',
            'backups.path' => public_path('backups'),
            'backups.schedule_enabled' => false,
        ]);

        $this->artisan('production:check')
            ->expectsOutputToContain('FAIL: APP_ENV must be production.')
            ->expectsOutputToContain('FAIL: APP_DEBUG must be false.')
            ->expectsOutputToContain('FAIL: APP_URL must be a valid HTTPS URL.')
            ->expectsOutputToContain('FAIL: DB_CONNECTION must be mysql')
            ->expectsOutputToContain('FAIL: BACKUP_PATH must be outside the public web root.')
            ->assertFailed();
    }

    public function test_hardened_production_configuration_passes_with_non_blocking_provider_warnings(): void
    {
        config([
            'app.env' => 'production',
            'app.key' => 'base64:'.base64_encode(str_repeat('k', 32)),
            'app.debug' => false,
            'app.url' => 'https://finance.example.test',
            'database.default' => 'mysql',
            'queue.default' => 'database',
            'session.encrypt' => true,
            'session.secure' => true,
            'session.http_only' => true,
            'session.same_site' => 'strict',
            'backups.path' => storage_path('backups'),
            'backups.schedule_enabled' => false,
            'mail.default' => 'log',
            'cache.default' => 'database',
        ]);

        $this->artisan('production:check')
            ->expectsOutputToContain('WARN: Scheduled backups are disabled.')
            ->expectsOutputToContain('WARN: MAIL_MAILER is still log.')
            ->expectsOutputToContain('Production configuration gate passed.')
            ->assertSuccessful();
    }
}
