using System;
using System.Collections.Generic;
using System.Text;
using ChuPiao.Common.Enums;
using ChuPiao.Common.Models;

namespace ChuPiao.AutoPrint.Configuration
{

    public class WorkingTimeConfigurator
    {
        /// <summary>
        /// 判断是否为彩票机可出票时间
        /// </summary>
        /// <param name="lotId"></param>
        /// <param name="now"> </param>
        /// <returns></returns>
        private static bool IsAllowPrintTime(int lotId, DateTime now)
        {
            DateTime startTime = DateTime.MinValue;//非出票起始时间
            DateTime endTime = DateTime.MinValue;//非出票结束时间

            //2014世界杯（2014.6.13-2014.7.14）期间，竞彩的官方销售时间需要特殊判断
            if (now < DateTime.Parse("2014-06-13") || now > DateTime.Parse("2014-07-15"))
            {
                switch (now.DayOfWeek)
                {
                    case DayOfWeek.Sunday:
                    case DayOfWeek.Monday:
                        startTime = new DateTime(now.Year, now.Month, now.Day, 1, 0, 0);
                        endTime = new DateTime(now.Year, now.Month, now.Day, 9, 0, 0);
                        break;
                    case DayOfWeek.Tuesday:
                    case DayOfWeek.Friday:
                    case DayOfWeek.Saturday:
                        startTime = new DateTime(now.Year, now.Month, now.Day, 0, 0, 0);
                        endTime = new DateTime(now.Year, now.Month, now.Day, 9, 0, 0);
                        break;
                    case DayOfWeek.Wednesday:
                    case DayOfWeek.Thursday:
                        switch ((Lottype)lotId)
                        {
                            case Lottype.Jz:
                                startTime = new DateTime(now.Year, now.Month, now.Day, 0, 0, 0);
                                endTime = new DateTime(now.Year, now.Month, now.Day, 9, 0, 0);
                                break;
                            case Lottype.Jl:
                                startTime = new DateTime(now.Year, now.Month, now.Day, 0, 0, 0);
                                endTime = new DateTime(now.Year, now.Month, now.Day, 7, 30, 0);
                                break;
                            case Lottype.Jm:
                                startTime = new DateTime(now.Year, now.Month, now.Day, 0, 0, 0);
                                endTime = new DateTime(now.Year, now.Month, now.Day, 9, 0, 0);
                                break;
                        }
                        break;
                }
            }
            else
            {
                int date = Convert.ToInt32(now.ToString("yyyyMMdd"));
                switch (date)
                {
                    case 20140613:
                    case 20140624:
                    case 20140625:
                    case 20140626:
                    case 20140627:
                    case 20140629:
                    case 20140630:
                    case 20140701:
                    case 20140702:
                    case 20140705:
                    case 20140706:
                    case 20140709:
                    case 20140710:
                    case 20140713:
                        //4-9
                        startTime = new DateTime(now.Year, now.Month, now.Day, 4, 0, 0);
                        endTime = new DateTime(now.Year, now.Month, now.Day, 9, 0, 0);
                        break;
                    case 20140614:
                    case 20140616:
                    case 20140617:
                    case 20140618:
                    case 20140619:
                    case 20140620:
                    case 20140621:
                    case 20140622:
                    case 20140623:
                        //6-11
                        startTime = new DateTime(now.Year, now.Month, now.Day, 6, 0, 0);
                        endTime = new DateTime(now.Year, now.Month, now.Day, 11, 0, 0);
                        break;
                    case 20140615:
                        //9-14
                        startTime = new DateTime(now.Year, now.Month, now.Day, 9, 0, 0);
                        endTime = new DateTime(now.Year, now.Month, now.Day, 14, 0, 0);
                        break;
                    case 20140628:
                    case 20140703:
                    case 20140704:
                    case 20140707:
                    case 20140708:
                    case 20140711:
                    case 20140712:
                        //0-9
                        startTime = new DateTime(now.Year, now.Month, now.Day, 0, 0, 0);
                        endTime = new DateTime(now.Year, now.Month, now.Day, 9, 0, 0);
                        break;
                    case 20140714:
                        //3-9
                        startTime = new DateTime(now.Year, now.Month, now.Day, 3, 0, 0);
                        endTime = new DateTime(now.Year, now.Month, now.Day, 9, 0, 0);
                        break;
                }
            }
            if (now >= startTime && now <= endTime)
            {
                return false;
            }
            return true;
        }

        /// <summary>
        /// 判断当期是否可出票
        /// </summary>
        /// <param name="lotId"></param>
        /// <param name="now"></param>
        /// <returns></returns>
        public static bool CanPrint(int lotId, DateTime now)
        {
            //S_SysConfigEntity entity = S_SysConfigCacheService.GetSysConfigByKey((int)SysConfigType.LimitCancelOperate);
            //if (entity != null && entity.Sc_IsUse && entity.Sc_Value == "1")
            //{
            //    return IsAllowPrintTime(lotId, now);
            //}
            //else
            //{
                return true;
            //}
        }
    }
}
