using ladaexpress.vn.Infrastructures.DTO.Models.Seo;

namespace ladaexpress.vn.Infrastructures.Services
{
    /// <summary>
    /// Service để tạo và quản lý sitemap.xml
    /// </summary>
    public interface ISitemapService
    {
        /// <summary>
        /// Tạo sitemap.xml hoàn chỉnh
        /// </summary>
        /// <returns>XML content của sitemap</returns>
        Task<string> GenerateSitemapXmlAsync();

        /// <summary>
        /// Tạo sitemap index cho các sitemap con
        /// </summary>
        /// <returns>XML content của sitemap index</returns>
        Task<string> GenerateSitemapIndexXmlAsync();

        /// <summary>
        /// Tạo sitemap cho static pages
        /// </summary>
        /// <returns>Danh sách SitemapItem cho static pages</returns>
        Task<List<SitemapItem>> GetStaticPagesSitemapAsync();

        /// <summary>
        /// Tạo sitemap cho products/services
        /// </summary>
        /// <returns>Danh sách SitemapItem cho products</returns>
        Task<List<SitemapItem>> GetProductsSitemapAsync();

        /// <summary>
        /// Tạo sitemap cho posts/news
        /// </summary>
        /// <returns>Danh sách SitemapItem cho posts</returns>
        Task<List<SitemapItem>> GetPostsSitemapAsync();

        /// <summary>
        /// Tạo sitemap cho job posts
        /// </summary>
        /// <returns>Danh sách SitemapItem cho job posts</returns>
        Task<List<SitemapItem>> GetJobPostsSitemapAsync();

        /// <summary>
        /// Tạo sitemap cho categories
        /// </summary>
        /// <returns>Danh sách SitemapItem cho categories</returns>
        Task<List<SitemapItem>> GetCategoriesSitemapAsync();

        // GetTagsSitemapAsync() method removed - tags are excluded from sitemap

        /// <summary>
        /// Validate sitemap theo chuẩn XML
        /// </summary>
        /// <param name="sitemapXml">XML content</param>
        /// <returns>Danh sách lỗi validation</returns>
        List<string> ValidateSitemap(string sitemapXml);

        /// <summary>
        /// Tính toán stats của sitemap
        /// </summary>
        /// <returns>Thống kê sitemap</returns>
        Task<SitemapStats> GetSitemapStatsAsync();

        /// <summary>
        /// Lưu sitemap vào file
        /// </summary>
        /// <param name="sitemapXml">XML content</param>
        /// <param name="fileName">Tên file (mặc định: sitemap.xml)</param>
        /// <returns>Đường dẫn file đã lưu</returns>
        Task<string> SaveSitemapToFileAsync(string sitemapXml, string fileName = "sitemap.xml");
    }

    /// <summary>
    /// Model cho sitemap item
    /// </summary>
    public class SitemapItem
    {
        public string Url { get; set; } = string.Empty;
        public DateTime? LastModified { get; set; }
        public string ChangeFrequency { get; set; } = "monthly";
        public double Priority { get; set; } = 0.5;
        public List<string> Images { get; set; } = new List<string>();
        public Dictionary<string, object> Extensions { get; set; } = new Dictionary<string, object>();
    }

    /// <summary>
    /// Model cho thống kê sitemap
    /// </summary>
    public class SitemapStats
    {
        public int TotalUrls { get; set; }
        public int StaticPages { get; set; }
        public int Products { get; set; }
        public int Posts { get; set; }
        public int Categories { get; set; }
        public int Tags { get; set; }
        public int Images { get; set; }
        public DateTime GeneratedAt { get; set; }
        public long SizeInBytes { get; set; }
        public Dictionary<string, int> PriorityDistribution { get; set; } = new Dictionary<string, int>();
        public Dictionary<string, int> ChangeFrequencyDistribution { get; set; } = new Dictionary<string, int>();
    }
}