using Pms.DataLibrary.Models;
using Pms.DataLibrary.Order;
using Pms.Models;
using ProjectManagementSystem.Common.Config;
using ProjectManagementSystem.Common.Logger;
using ProjectManagementSystem.Common.WebApi;
using ProjectManagementSystem.Common.Models;
using ProjectManagementSystem.WebApi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using ProjectManagementSystem.Common.Function;
using DbCommon.BusinessCore.BaseCore;
using ProjectManagementSystem.Common.Extenions;

namespace ProjectManagementSystem.TaskBookEvent
{
    public class TaskBookRegister
    {
        public TaskBookRegister()
        {
            new TaskBookBehavior_63000();
            new TaskBookBehavior_63001();
            new TaskBookBehavior_63002();
            new TaskBookBehavior_63003();

            new TaskBookBehavior_63004();
            new TaskBookBehavior_63005();
            new TaskBookBehavior_63006();
            //new TaskBookBehavior_63007();
            new TaskBookBehavior_63008();
            new TaskBookBehavior_63009();
            new TaskBookBehavior_63010();

            //new TaskBookBehavior_63011();
            //new TaskBookBehavior_63012();

            new TaskBookBehavior_63020();
            new TaskBookBehavior_63021();
            new TaskBookBehavior_63022();

            new TaskBookBehavior_63030();
            new TaskBookBehavior_63031();
            new TaskBookBehavior_63032();

            new TaskBookBehavior_63040();
            new TaskBookBehavior_63041();

            InitBehaviorCustom();
            CLog.Instance.SystemLog.WriteDebug($"TaskBookRegister已注册");
        }

        private void InitBehaviorCustom()
        {
            var plcBehaviorList = ExcelConfig.Instance.PlcBehaviorList;
            foreach (var data in plcBehaviorList)
            {
                if(data.IsIOTrans)
                {
                    new TaskBookBehavior_IOAddress(data.Behavior);
                }
                else
                {
                    switch (data.DbValueDataType)
                    {
                        case null:
                        case "":
                        case "bool":
                            new TaskBookBehavior_PLC<bool>(data.Behavior);
                            break;
                        case "byte":
                            new TaskBookBehavior_PLC<byte>(data.Behavior);
                            break;
                        case "short":
                        case "int16":
                            new TaskBookBehavior_PLC<short>(data.Behavior);
                            break;
                        case "ushort":
                        case "uint16":
                            new TaskBookBehavior_PLC<ushort>(data.Behavior);
                            break;
                        case "int":
                        case "int32":
                            new TaskBookBehavior_PLC<int>(data.Behavior);
                            break;
                        case "uint":
                        case "uint32":
                            new TaskBookBehavior_PLC<uint>(data.Behavior);
                            break;
                        case "long":
                        case "int64":
                            new TaskBookBehavior_PLC<long>(data.Behavior);
                            break;
                        case "ulong":
                        case "uint64":
                            new TaskBookBehavior_PLC<ulong>(data.Behavior);
                            break;
                        case "string":
                            new TaskBookBehavior_PLC<string>(data.Behavior);
                            break;
                        default:
                            CLog.Instance.SystemLog.WriteError($"{data.Behavior} 未知的PLC数据类型 {data.DbValueDataType}");
                            break;
                    }
                    
                }
                
            }
        }
    }
}
