<?php

declare(strict_types=1);

final class MyronRobotsTxtGenerator
{
    public function __construct(
        private readonly array $siteSettings,
    ) {
    }

    public function generate(): string
    {
        $override = trim((string) ($this->siteSettings['seo_robots_txt_override'] ?? ''));
        if ($override !== '') {
            return rtrim((string) ($this->siteSettings['seo_robots_txt_override'] ?? ''), "\r\n") . "\n";
        }

        return "User-agent: *\n"
            . "Disallow:\n\n"
            . 'Sitemap: ' . rtrim(myronAppUrl(), '/') . myronBuildPublicPageUrl('/sitemap.xml') . "\n";
    }
}
