<?php

namespace App\SiteReadiness\Checks;

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

class ComposerLockTrackedCheck implements ReadinessCheck
{
    public function group(): string { return 'Environment'; }
    public function label(): string { return 'composer.lock tracked in git'; }
    public function hint(): string { return 'Run git add -f composer.lock so deploys install pinned versions.'; }

    public function run(): CheckResult
    {
        $tracked = trim((string) @shell_exec('cd ' . escapeshellarg(base_path()) . ' && git ls-files composer.lock 2>/dev/null')) !== '';
        if ($tracked) {
            return new CheckResult(Status::OK, 'composer.lock is tracked in git.');
        }
        return new CheckResult(Status::WARN, 'composer.lock is not tracked in git.');
    }
}
