using OASystem.Domain.Entities.PersonnelModule;
using OASystem.Domain.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OASystem.Domain.ViewModels.PersonnelModule
{
    /// <summary>
    /// 物品详细信息 View
    /// </summary>
    public class GoodsInfoView:Pm_GoodsInfo
    {
    }

    #region 物品领用List


    [SugarTable(tableName: "Pm_GoodsInfo", tableDescription: "物品信息表")]
    public class GoodsListView
    {
        [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
        public int Id { get; set; }

        public string Name { get; set; }

        public int Type { get; set; }

        [SugarColumn(IsIgnore = true)]
        public string TypeName { get; set; }

        public decimal StockQuantity { get; set; }

        //SugarColumn(IsIgnore = true),

        [Navigate(NavigateType.OneToMany, nameof(GoodsListReceiveView.GoodsId))]
        //[Navigate(NavigateType.OneToMany, nameof(GoodsListReceiveView.GoodsId), nameof(Id))]
        public List<GoodsListReceiveView> Receives { get; set; }//注意禁止给books手动赋值


        [SugarColumn(IsIgnore = true)]
        public decimal WaitAuditQuantity
        {
            get
            {
                var quantity = 0.00M;
                if (Receives.Count > 0)
                {
                    quantity = Receives.Sum(x => x.Quantity);
                }
                return quantity;
            }
        }


        [SugarColumn(IsIgnore = true)]
        public string StockQuantityLabel
        {
            get
            {
                var str = "";
                if (WaitAuditQuantity > 0)
                {
                    str = $"物品待审核数量合计:{WaitAuditQuantity.ToString("#0.00")}";
                }

                return str;
            }
        }

        public int LastUpdateUserId { get; set; }

        [Navigate(NavigateType.OneToOne, nameof(Type))]
        public GoodsListSetDataView TypeData { get; set; }

        [Navigate(NavigateType.OneToOne, nameof(LastUpdateUserId))]
        public GoodsListUsersView UserData { get; set; }

        public DateTime LastUpdateTime { get; set; }

        public string Remark { get; set; }

        public int IsDel { get; set; }
    }


    [SugarTable(tableName: "Pm_GoodsReceive", tableDescription: "物品领用表")]
    public class GoodsListReceiveView
    {
        [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
        public int Id { get; set; }
        /// <summary>
        /// 商品Id
        /// Pm_GoodsInfo Id
        /// </summary>
        public int GoodsId { get; set; }

        /// <summary>
        /// 领用数量
        /// </summary>
        public decimal Quantity { get; set; }

        /// <summary>
        /// 审核状态
        /// </summary>
        public GoodsAuditEnum AuditStatus { get; set; } = GoodsAuditEnum.Pending;

        public int IsDel { get; set; }

    }

    [SugarTable(tableName: "Sys_SetData", tableDescription: "")]
    public class GoodsListSetDataView
    {
        [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
        public int Id { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public string Name { get; set; }
    }
    [SugarTable(tableName: "Sys_Users", tableDescription: "")]
    public class GoodsListUsersView
    {
        [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
        public int Id { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public string CnName { get; set; }
    }
    #endregion


    /// <summary>
    /// 物品类型View
    /// </summary>
    [SugarTable("Sys_SetDataType")]
    public class GoodsTypeView
    {
        /// <summary>
        /// 物品类型Id
        /// </summary>
        [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
        public int Id { get; set; }

        public string Name { get; set; }

        [Navigate(NavigateType.OneToMany, nameof(GoodsSubTypeView.STid))]
        public List<GoodsSubTypeView> SubTypeItems { get; set; }

        public string Remark { get; set; }
        
        public int IsDel { get; set; }
    }

    /// <summary>
    /// 物品Sub类型
    /// View
    /// </summary>
    [SugarTable("Sys_SetData")]
    public class GoodsSubTypeView
    {
        /// <summary>
        /// 物品类型Id
        /// </summary>
        [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
        public int Id { get; set; }

        public int STid { get; set; }

        public string Name { get; set; }

        public int IsDel { get; set; }
    }

    public class GoodsReceiveView
    {

        public int Id { get; set; }
        public int GroupId { get; set; }
        public int GoodsId { get; set; }
        public string GoodsName { get; set; }
        public decimal Quantity { get; set; }
        public string Reason { get; set; }
        public string Remark { get; set; }
        public GoodsAuditEnum AuditStatus { get; set; }
        public string AuditStatusText { get { return AuditStatus.GetEnumDescription(); } }
        public int AuditUserId { get; set; }
        public string AuditUserName { get; set; }
        public DateTime AuditTime { get; set; }
        public string CreateUserName { get; set; }
        public DateTime CreateTime { get; set; }
    }
    /// <summary>
    /// 
    /// </summary>
    public class GoodsReceiveListView: GoodsReceiveView
    {
        public string GoodsType { get; set; }
    }

    public class GoodsReceiveListMobileView : GoodsReceiveListView
    {
        public string GroupName { get; set; }
    }

    /// <summary>
    /// 
    /// </summary>
    public class GoodsReceiveInfoView : GoodsReceiveView
    {
        public string GoodsStorageInfo { get; set; }
        public object? QuantityInfos { get; set; }
        public object? GoodsStorageInfoStr { get; set; }

        public string GoodsType { get; set; }
    }


    public class GoodsReceiveInfoMobileView : GoodsReceiveInfoView
    {
        public string GroupName { get; set; }
    }


    /// <summary>
    /// 
    /// </summary>
    public class GoodsReceiveLinkStorageView
    {
        public int StorageId { get; set; }
        public decimal Quantity { get; set; }
    }
}