<?php

declare(strict_types=1);

namespace App\Http\Controllers;

use Illuminate\Http\Response;
use Illuminate\Support\Facades\Config;

final class RobotsController extends Controller
{
    public function __invoke(): Response
    {
        $allow = (bool) (Config::get('settings.seo_allow_indexing', true));

        if (! $allow) {
            $body = "User-agent: *\nDisallow: /\n";

            return response($body, 200)->header('Content-Type', 'text/plain; charset=UTF-8');
        }

        $sitemapLine = 'Sitemap: '.url('/sitemap.xml');
        $body = "User-agent: *\nAllow: /\n\n{$sitemapLine}\n";

        return response($body, 200)->header('Content-Type', 'text/plain; charset=UTF-8');
    }
}
