<?php

namespace App\SiteReadiness\Checks;

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

class SiteIdentityCheck implements ReadinessCheck
{
    /**
     * Maps config key => shipped placeholder default.
     * A value that is empty or equals the placeholder is considered not ready.
     */
    private const FIELDS = [
        'site.address.location'  => '1 Example Street',
        'site.address.address_1' => 'Example',
        'site.address.address_2' => 'Example',
        'site.address.postcode'  => 'AA1 AA1',
        'site.address.reg_no'    => '999999',
        'site.address.gphc_no'   => '999999',
        'site.tnx_prefix'        => 'MTC',
    ];

    public function group(): string { return 'Identity'; }
    public function label(): string { return 'Company identity fields set'; }
    public function hint(): string { return 'Complete the company/legal identity fields (legal requirement) in site settings.'; }

    public function run(): CheckResult
    {
        $prod = config('app.env') === 'production';

        $notReady = [];
        foreach (self::FIELDS as $key => $placeholder) {
            $value = config($key);
            if (empty($value) || $value === $placeholder) {
                $notReady[] = $key;
            }
        }

        if (empty($notReady)) {
            return new CheckResult(Status::OK, 'All company identity fields are configured.');
        }

        $detail = 'Not configured: ' . implode(', ', $notReady) . '.';

        return new CheckResult(
            $prod ? Status::FAIL : Status::WARN,
            $detail,
        );
    }
}
