using ClosedXML.Excel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LSFE.Domain.Helpers
{
    public class ExcelTemplateValidator
    {
        private static readonly string[] REQUIRED_HEADERS = new[]
        {
        "BRAND", "January", "February", "March", "April", "May", "June",
        "July", "August", "September", "October", "November", "December",
        "Year", "Medrep_Name"
    };

        public static (bool isValid, List<string> errors) ValidateHeaders(IXLWorksheet worksheet)
        {
            var errors = new List<string>();
            var isValid = true;

            for (int col = 1; col <= REQUIRED_HEADERS.Length; col++)
            {
                var headerValue = worksheet.Cell(1, col).Value.ToString()?.Trim();
                var expectedHeader = REQUIRED_HEADERS[col - 1];

                if (string.IsNullOrEmpty(headerValue) ||
                    !headerValue.Equals(expectedHeader, StringComparison.OrdinalIgnoreCase))
                {
                    errors.Add($"Column {col}: Expected '{expectedHeader}' but found '{headerValue}'");
                    isValid = false;
                }
            }

            return (isValid, errors);
        }
    }
}
