using ladaexpress.vn.Infrastructures.Services;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace ladaexpress.vn.Controllers
{
    public class UrlRecordController : Controller
    {
        private readonly IUrlRecordService _urlRecordService;
        private readonly ISitemapService _sitemapService;

        public UrlRecordController(IUrlRecordService urlRecordService, ISitemapService sitemapService)
        {
            _urlRecordService = urlRecordService;
            _sitemapService = sitemapService;
        }

        [HttpGet("SiteMapXml")]
        public async Task<IActionResult> SiteMapXml()
        {
            // Use the new SitemapService with image support
            var siteMap = await _sitemapService.GenerateSitemapXmlAsync();

            // Set proper headers to prevent script injection
            Response.Headers["Cache-Control"] = "public, max-age=3600";
            Response.Headers["X-Content-Type-Options"] = "nosniff";

            return Content(siteMap, "application/xml; charset=utf-8");
        }

        [HttpGet("Robot")]
        public async Task<IActionResult> Robot()
        {
            var robots = await _urlRecordService.GenerateRobots();
            return Content(robots, "text/plain");
        }

    }
}
