//using System.Data;
//using Common;
//using Common.Soap;
//using Database;
//using Database.Database;
//using GuesssongNC.Worker.Utils;
//using Quartz;
//namespace GuesssongNC.Worker;
//class WeeklyPrizeScheduler : IJob
//{
// private static readonly log4net.ILog log = log4net.LogManager.GetLogger(
// typeof(WeeklyPrizeScheduler)
// );
// IConfiguration configuration;
// ModelContext dbContext;
// public WeeklyPrizeScheduler(IConfiguration _configuration)
// {
// configuration = _configuration;
// dbContext = new DbHelper().GetDbContext(configuration.GetSection("Connection").Value!);
// }
// public async Task Execute(IJobExecutionContext context)
// {
// log.Info("Start WeeklyPrizeScheduler ...");
// try
// {
// var result = await CommonSoapHandler.ExecuteAsync(
// "http://127.0.0.1:8510/WsMytel?wsdl",
// @"
//
//
//
//ws_guesssong
//guesssong@2025#
//GUESSSONG_PACKAGEDAILY
//9665750225
//20250114090157
//0
//REAL
//149
//0400000220250114090156769
//MONFEE
//#CONTENT
//
//
//'"
// );
// var prizes1 = dbContext
// .Prizes.Where(x => x.Type == CommonConstants.MonthlyPrize)
// .OrderBy(x => x.Priority)
// .ToList();
// // foreach (var p in prizes1)
// // {
// // // send sms to user
// // var msg = dbContext
// // .Configs.Where(x => x.ParamName == (CommonConstants.Monthly + "_" + p.Amount))
// // .FirstOrDefault();
// // if (msg != null)
// // {
// // await CommonLogic.SendMtToUserAsync(
// // dbContext,
// // "959665750225",
// // msg.ParamValueFr
// // );
// // }
// // }
// // send sms to user
// var msg = dbContext
// .Configs.Where(x => x.ParamName == (CommonConstants.Monthly + "_500000"))
// .FirstOrDefault();
// if (msg != null)
// {
// await CommonLogic.SendMtToUserAsync(dbContext, "959698091436", msg.ParamValueFr);
// }
// // check in monday
// DateTime now = DateTime.Now;
// var dayOfWeek = now.DayOfWeek;
// if (dayOfWeek != DayOfWeek.Monday)
// {
// // return;
// }
// List> timeWeekly = CommonLogic.GetTimeWeekly(1);
// log.Debug($"WEEKLY from {timeWeekly[0][0]} to {timeWeekly[0][1]}");
// var weeklyTerm = dbContext
// .Terms.Where(
// x =>
// x.Type == CommonConstants.Weekly
// && x.Status == CommonConstants.ActiveInt
// && x.DrawTime >= timeWeekly[0][0]
// && x.DrawTime <= timeWeekly[0][1]
// )
// .FirstOrDefault();
// if (weeklyTerm == null)
// {
// log.Info("No weekly term found.");
// weeklyTerm = new Term()
// {
// Id = (decimal)await DbLogic.GenIdAsync(dbContext, "term_seq"),
// Name = "Weekly Term",
// Code = CommonConstants.Weekly,
// FromTime = timeWeekly[0][0],
// ToTime = timeWeekly[0][1],
// DrawTime = timeWeekly[0][1].AddMinutes(-30),
// Status = CommonConstants.ActiveInt,
// Type = CommonConstants.Weekly
// };
// dbContext.Terms.Add(weeklyTerm);
// await dbContext.SaveChangesAsync();
// }
// // check highest point
// var termUserPrize = dbContext
// .TermUserPrizes.Where(
// x =>
// x.TimeCalculate >= weeklyTerm.FromTime
// && x.TimeCalculate <= weeklyTerm.ToTime
// )
// .Count();
// if (termUserPrize > 0)
// {
// log.Info($"Term {weeklyTerm.Id} has {termUserPrize} prize");
// return;
// }
// // get point
// var userHighestPoint = dbContext
// .PlayTransactions.Where(
// x =>
// x.Status == CommonConstants.Submited
// && x.TimeSubmit > weeklyTerm.FromTime
// && x.TimeSubmit < weeklyTerm.ToTime
// )
// .GroupBy(x => x.Msisdn)
// .Select(x => new { Msisdn = x.Key, Points = x.Sum(y => y.TotalPoint) })
// .OrderByDescending(x => x.Points)
// .Skip(0)
// .Take(10)
// .ToList();
// var prizes = dbContext
// .Prizes.Where(x => x.Type == CommonConstants.WeeklyPrize)
// .OrderBy(x => x.Priority)
// .ToList();
// for (int i = 0; i < prizes.Count(); i++)
// {
// var prize = prizes[i];
// if (userHighestPoint.Count <= i)
// {
// continue;
// }
// var user = userHighestPoint[i];
// bool addPoint = await LogicUtils.AddingPointForUserAsync(
// configuration,
// dbContext,
// user.Msisdn,
// user.Points ?? 0,
// weeklyTerm,
// prize
// );
// }
// }
// catch (Exception exception)
// {
// log.Error("Exception: ", exception);
// }
// }
//}