<?php

namespace App\Http\Controllers;

use App\Models\SeoSetting;

class RobotsTxtController extends Controller
{
    public function index()
    {
        $seo = SeoSetting::current();

        $content = $seo->robots_txt;

        if (blank($content)) {
            $content = implode("\n", [
                'User-agent: *',
                'Allow: /',
                'Disallow: /admin/',
                'Disallow: /user/',
                'Disallow: /login',
                'Disallow: /register',
                'Disallow: /forgot-password',
                'Disallow: /reset-password/',
                'Disallow: /email/',
                'Disallow: /verify-email/',
                'Disallow: /password/',
                'Disallow: /subscription/',
                'Disallow: /dashboard/',
                'Sitemap: ' . url('/sitemap.xml'),
            ]);
        }

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