<?php

namespace App\SiteReadiness\Checks;

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

class AppUrlCheck implements ReadinessCheck
{
    public function group(): string { return 'Environment'; }
    public function label(): string { return 'Live URL configured'; }
    public function hint(): string { return 'Set APP_URL to the live https:// domain in .env.'; }

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

        if ($url === '') {
            return new CheckResult($prod ? Status::FAIL : Status::WARN, 'APP_URL is empty.');
        }
        if (str_contains($url, 'mtcserver') || str_contains($url, 'mtcdevserver')) {
            return new CheckResult($prod ? Status::FAIL : Status::WARN, 'APP_URL still points at an mtc dev/staging host.');
        }
        if (!str_starts_with($url, 'https://')) {
            return new CheckResult($prod ? Status::FAIL : Status::WARN, 'APP_URL is not https.');
        }
        return new CheckResult(Status::OK, 'APP_URL = ' . $url);
    }
}
