using RDH.Data.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace RDH.Data.BLL
{
    public partial class StorageSpaceItemBLL : BaseOrclSnapshotBLL<StorageSpaceItem>
    {
        public StorageSpaceItemBLL() : base()
        {
            AliasTableName = "si";
        }

        internal override String TABLE_NAME { get { return "STORAGE_SPACE_ITEM"; } }//TB_NAME
        internal override string ENTITY_NAME { get { return "StorageSpaceItem"; } }
        internal override String KEY_COLUMN { get { return "SNAPSHOT_KEY"; } }//KEY_COLUMN
        internal override string SNAPSHOT_BASE { get { return "STORAGE_SPACE_ITEM_BASE"; } }

        internal override void InitMaps()
        {
            ColumnPropMaps.Add("SNAPSHOT_KEY", "SnapshotKey");
            ColumnPropMaps.Add("KEY", "Key");
            ColumnPropMaps.Add("STORAGE_SPACE_KEY", "StorageSpaceKey");
            ColumnPropMaps.Add("MAX_QUANTITY", "MaxQuantity");
            ColumnPropMaps.Add("ALART_QUANTITY", "AlartQuantity");
            ColumnPropMaps.Add("CURRENT_QUANTITY", "CurrentQuantity");
            ColumnPropMaps.Add("CREATE_BY", "CreateBy");
            ColumnPropMaps.Add("CREATE_TIME", "CreateTime");
            ColumnPropMaps.Add("IS_ALLOW_MULTI_LOT", "IsAllowMultiLot");
            ColumnPropMaps.Add("ITEM_KEY", "ItemKey");
            ColumnPropMaps.Add("DEVICE_KEY", "DeviceKey");
            ColumnPropMaps.Add("FLAG", "Flag");
            ColumnPropMaps.Add("CLIENT_TIME", "ClientTime");
            ColumnPropMaps.Add("SERVER_TIME", "ServerTime");
            ColumnPropMaps.Add("EXT01", "Ext01");
            ColumnPropMaps.Add("EXT02", "Ext02");
            ColumnPropMaps.Add("EXT03", "Ext03");
            ColumnPropMaps.Add("EXT04", "Ext04");
            ColumnPropMaps.Add("EXT05", "Ext05");
            ColumnPropMaps.Add("EXT06", "Ext06");
            ColumnPropMaps.Add("EXT07", "Ext07");
            ColumnPropMaps.Add("EXT08", "Ext08");
            ColumnPropMaps.Add("EXT09", "Ext09");
            ColumnPropMaps.Add("EXT10", "Ext10");//COLUMN_MAPS
        }

        internal override object GetParam(StorageSpaceItem storagespaceitem)
        {
            return new
            {
                SnapshotKey = storagespaceitem.SnapshotKey,
                Key = storagespaceitem.Key,
                StorageSpaceKey = storagespaceitem.StorageSpaceKey,
                MaxQuantity = storagespaceitem.MaxQuantity,
                AlartQuantity = storagespaceitem.AlartQuantity,
                CurrentQuantity = storagespaceitem.CurrentQuantity,
                CreateBy = storagespaceitem.CreateBy,
                CreateTime = storagespaceitem.CreateTime,
                IsAllowMultiLot = storagespaceitem.IsAllowMultiLot,
                ItemKey = storagespaceitem.ItemKey,
                DeviceKey = storagespaceitem.DeviceKey,
                Flag = storagespaceitem.Flag,
                ClientTime = storagespaceitem.ClientTime,
                ServerTime = storagespaceitem.ServerTime,
                Ext01 = storagespaceitem.Ext01,
                Ext02 = storagespaceitem.Ext02,
                Ext03 = storagespaceitem.Ext03,
                Ext04 = storagespaceitem.Ext04,
                Ext05 = storagespaceitem.Ext05,
                Ext06 = storagespaceitem.Ext06,
                Ext07 = storagespaceitem.Ext07,
                Ext08 = storagespaceitem.Ext08,
                Ext09 = storagespaceitem.Ext09,
                Ext10 = storagespaceitem.Ext10,   //Params
            };
        }
        public StorageSpaceItem GetByStorageAndItem(StorageSpace storage, Guid itemKey)
        {
            SqlBuilder sqlBuilder = new SqlBuilder(this);
            sqlBuilder.AppendWherePhrases("si.STORAGE_SPACE_KEY=:storageKey AND si.ITEM_KEY=:itemKey");
            return SqlMapper.Query<StorageSpaceItem>(ConnectionFactory.Current.GetSessionConnection(),
                sqlBuilder.ToString(),
                new
                {
                    storageKey = storage.Key,
                    itemKey = itemKey
                }).FirstOrDefault();
        }
    }
}
