<?php

namespace App\SiteReadiness\Checks;

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

class SiteEmailsSetCheck implements ReadinessCheck
{
    private const PLACEHOLDER = 'sales@mtc.co.uk';

    public function group(): string { return 'Mail'; }
    public function label(): string { return 'Site email addresses set'; }
    public function hint(): string { return 'Set the from/shop/contact email addresses for this site.'; }

    public function run(): CheckResult
    {
        $fields = [
            'from_email'     => config('site.from_email'),
            'shop_email'     => config('site.shop_email'),
            'contact_email'  => config('site.contact_email'),
        ];

        $placeholders = [];
        foreach ($fields as $key => $value) {
            if (empty($value) || $value === self::PLACEHOLDER) {
                $placeholders[] = $key;
            }
        }

        if (empty($placeholders)) {
            return new CheckResult(Status::OK, 'All site email addresses are configured.');
        }

        return new CheckResult(
            Status::WARN,
            'Placeholder or empty email address for: ' . implode(', ', $placeholders) . '.',
        );
    }
}
