// using BMA.EHR.Core;
using BMA.EHR.Recurit.Exam.Service.Extensions;
using BMA.EHR.Recurit.Exam.Service.Models;
using BMA.EHR.Recurit.Exam.Service.Services;
using Newtonsoft.Json;
using OfficeOpenXml;
using System.Linq;

namespace BMA.EHR.Recurit.Exam.Service.Data
{
    public static class DatabaseSeeder
    {

        #region " Seed Metadata "

        public static async Task SeedPeriodExamAsync(WebApplication app)
        {
            // using var scope = app.Services.CreateScope();
            // var service = scope.ServiceProvider.GetRequiredService<PeriodExamService>();

            // var insertedPeriodExam = new List<PeriodExam>();

            // if ((await service.GetsAsync()).Count() == 0)
            // {
            //     // read excels into object
            //     var excelFile = "SeedPeriodExam.xlsx";
            //     using (var excel = new ExcelPackage(new FileInfo(excelFile)))
            //     {
            //         // 1. Seed PeriodExam
            //         var workSheet = excel.Workbook.Worksheets.FirstOrDefault(x => x.Name.ToLower() == "periodexam");
            //         var totalRows = workSheet?.Dimension.Rows;

            //         int row = 2;

            //         while (row <= totalRows)
            //         {
            //             var cell1 = workSheet?.Cells[row, 1]?.GetValue<string>();
            //             if (cell1 == "" || cell1 == null) break;

            //             var PeriodExam = insertedPeriodExam.Where(x => x.Name == (workSheet?.Cells[row, 1]?.GetValue<string>() ?? "")).FirstOrDefault();
            //             if (PeriodExam == null)
            //             {

            //                 var inserted = new PeriodExam
            //                 {
            //                     Id = Guid.NewGuid(),
            //                     Name = workSheet?.Cells[row, 1]?.GetValue<string>() ?? "",
            //                     Round = workSheet?.Cells[row, 2]?.GetValue<int>() ?? 0,
            //                     Fee = workSheet?.Cells[row, 3]?.GetValue<float>() ?? 0,
            //                     // StartDate = workSheet?.Cells[row, 4]?.GetValue<DateTime>() ?? DateTime.Now.Date,
            //                     // EndDate = workSheet?.Cells[row, 5]?.GetValue<DateTime>() ?? DateTime.Now.Date,
            //                     Year = workSheet?.Cells[row, 6]?.GetValue<int>() ?? 0,
            //                     // AnnounceDate = workSheet?.Cells[row, 7]?.GetValue<DateTime>() ?? DateTime.Now.Date,
            //                     IsActive = true,
            //                     CreatedFullName = "System Administrator",
            //                     CreatedAt = DateTime.Now
            //                 };
            //                 insertedPeriodExam.Add(inserted);

            //                 await service.CreateAsync(inserted);
            //             }
            //             row++;
            //         }
            //     }
            // }
        }
        #endregion
    }
}
