<?php

namespace App\SiteReadiness\Checks;

use App\SiteReadiness\CheckResult;
use App\SiteReadiness\ReadinessCheck;
use App\SiteReadiness\Status;

class EncryptionEnabledCheck implements ReadinessCheck
{
    public function group(): string { return 'Environment'; }
    public function label(): string { return 'Field encryption enabled'; }
    public function hint(): string { return 'Set ENCRYPTION_ENABLED=true and ensure APP_KEY is set; run php artisan encryption:run.'; }

    public function run(): CheckResult
    {
        $enabled = (bool) config('encryption.enabled');
        $hasKey = !empty(config('app.key'));
        $prod = config('app.env') === 'production';

        if ($enabled && $hasKey) {
            return new CheckResult(Status::OK, 'Encryption enabled and APP_KEY present.');
        }
        $detail = !$enabled ? 'ENCRYPTION_ENABLED is off.' : 'APP_KEY is not set.';
        return new CheckResult($prod ? Status::FAIL : Status::WARN, $detail);
    }
}
