using Kivii.DataAnnotations;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Kivii.Samples.Entities
{
    public class Sample : EntityWithMetadata, IEntityInAssemblyDb, IEntityHasRemark, IEntityHasCreator, IEntityHasUpdater
    {
        #region 第三方关联V1.0
        [ApiMember(Description = "关联业务,例如:此样品用于具体某一报告,此处记录报告信息")]
        [InternalSetter]
        [StringLength(200), Default("")]
        public string BizId { get; set; }

        [ApiMember(Description = "业务Kvid")]
        [InternalSetter]
        [DefaultEmptyGuid]
        public Guid BizKvid { get; set; }

        [ApiMember(Description = "业务类型,指实体类型全名称")]
        [InternalSetter]
        [StringLength(200), Default("")]
        public string BizType { get; set; }

        [InternalSetter]
        [DefaultEmptyGuid]
        public Guid OwnerKvid { get; set; }

        [InternalSetter]
        [StringLength(500)]//所属信息，记录当前数据的所属信息，可以是部门可以是组织可以是个人
        public string OwnerName { get; set; }
        #endregion

        #region 关联信息
        [InternalSetter]
        [DefaultEmptyGuid]
        public Guid RootKvid { get; set; }

        [ApiMember(Description = "父级样品Kvid")]
        [DefaultEmptyGuid]
        public Guid ParentKvid { get; set; }

        [ApiMember(Description = "包裹名称")]
        [StringLength(200), Default("")]
        public string PackageName { get; set; }

        [ApiMember(Description = "包裹Kvid,只有在样品打包后会记录当前样品所属的包裹Kvid,包裹也是样品实体,包裹类型")]
        [DefaultEmptyGuid]
        public Guid PackageKvid { get; set; }

        [ApiMember(Description = "来源名称")]
        [IgnoreUpdate]
        [StringLength(200), Default("")]
        public string SourceName { get; set; }

        [ApiMember(Description = "来源编号,邮寄则为记录快递号,抽样则为计划编号")]
        [IgnoreUpdate]
        [StringLength(200), Default("")]
        public string SourceNumber { get; set; }

        [ApiMember(Description = "来源类型,例如是快递方式则记录,顺丰,中通等")]
        [IgnoreUpdate]
        [StringLength(200), Default("")]
        public string SourceType { get; set; }
        #endregion

        #region 基本信息

        [ApiMember(Description = "样品名称")]
        [Required]
        [StringLength(200)]
        public string Name { get; set; }

        [ApiMember(Description = "样品内部编号")]
        [StringLength(200), Default("")]
        public string InternalCode { get; set; }

        [ApiMember(Description = "样品编号")]
        [SerialNumber]
        [StringLength(100), Default("")]
        public string SerialNumber { get; set; }

        [ApiMember(Description = "样品批次编号")]
        [StringLength(200), Default("")]
        public string BatchNumber { get; set; }

        [ApiMember(Description = "样品类型,类型:主样,子样,包裹")]
        [StringLength(50), Default("")]
        public SampleType Type { get; set; }

        #region 时间相关

        [ApiMember(Description = "抽样时间,一般用于监督,委托抽样使用")]
        public DateTime? SamplingTime { get; set; }

        [ApiMember(Description = "登记时间")]
        public DateTime? RegistTime { get; set; }

        [ApiMember(Description = "检验开始日期")]
        public DateTime? TestStartDate { get; set; }

        [ApiMember(Description = "检验结束日期")]
        public DateTime? TestFinishDate { get; set; }

        [ApiMember(Description = "样品受理日期")]
        public DateTime? DealTime { get; set; }

        [ApiMember(Description = "样品完成日期")]
        public DateTime? DeadTime { get; set; }

        [ApiMember(Description = "操作日期")]
        public DateTime OperateTime { get; set; }
        #endregion
        [ApiMember(Description = "样品分类")]
        [StringLength(50), Default("")]
        public string Category { get; set; }

        [ApiMember(Description = "样品品牌")]
        [StringLength(200), Default("")]
        public string Brand { get; set; }

        [ApiMember(Description = "样品规格")]
        [StringLength(200), Default("")]
        public string Specification { get; set; }

        [ApiMember(Description = "样品型号")]
        [StringLength(200), Default("")]
        public string Model { get; set; }

        [ApiMember(Description = "样品材质")]
        [StringLength(200), Default("")]
        public string Material { get; set; }

        [ApiMember(Description = "样品品级")]
        [StringLength(200), Default("")]
        public string Grade { get; set; }

        [ApiMember(Description = "安全类别")]
        [StringLength(200), Default("")]
        public string GradeSafety { get; set; }

        [ApiMember(Description = "样品状况,一般是指收到样品时的状况，是否完好等")]
        [StringLength(200), Default("")]
        public string Condition { get; set; }
        #endregion

        #region 数量相关
        [ApiMember(Description = "样品数量")]
        [DecimalLength(10, 2), Default(0)]
        public decimal Quantity { get; set; }

        [ApiMember(Description = "数量单位")]
        [StringLength(50), Default("")]
        public string QuantityUnit { get; set; }
        #endregion

        #region 生产单位信息及生产日期
        [ApiMember(Description = "生产单位")]
        [StringLength(100), Default("")]
        public string ManufacturerName { get; set; }

        [ApiMember(Description = "生产单位Kvid")]
        [DefaultEmptyGuid]
        [IgnoreUpdate]
        public Guid ManufacturerKvid { get; set; }

        [ApiMember(Description = "生产单位联系人姓名")]
        [StringLength(50), Default("")]
        public string ManufacturerContactName { get; set; }

        [ApiMember(Description = "生产单位联系人Kvid")]
        [DefaultEmptyGuid]
        [IgnoreUpdate]
        public Guid ManufacturerContactKvid { get; set; }

        [ApiMember(Description = "生产单位联系人电话")]
        [StringLength(50), Default("")]
        //正则表达式验证：(^(\d{3,4}-)?\d{7,8})$|(13[0-9]{9})
        public string ManufacturerContactNumber { get; set; }

        [ApiMember(Description = "生产单位地址")]
        [StringLength(200), Default("")]
        public string ManufacturerAddress { get; set; }

        [ApiMember(Description = "生产日期")]
        public DateTime? ProductionDate { get; set; }
        #endregion

        #region 文本 备注
        [ApiMember(Description = "摘要")]
        [StringLength(1000), Default("")]
        public string Summary { get; set; }

        [ApiMember(Description = "备注")]
        [StringLength(1000), Default("")]
        public string Remark { get; set; }
        #endregion

        [Ignore]
        public DateTime? AssignTime { get; set; }

        /// <summary>
        /// 样品当前所在位置
        /// </summary>
        [Ignore]
        public Location CurrentLocation { get; set; }

        /// <summary>
        /// 样品当前最新的路由信息
        /// </summary>
        [Ignore]
        public Route CurrentRoute { get; set; }

        /// <summary>
        /// 样品的所有路由信息
        /// </summary>
        [Ignore]
        public List<Route> Routes { get; set; }

        /// <summary>
        /// 当前样品下一级的子样品信息
        /// </summary>
        [Ignore]
        public List<Sample> Childrens { get; set; }

        /// <summary>
        /// 当前样品所在包裹的完整信息
        /// </summary>
        [Ignore]
        public Sample CurrentPackage { get; set; }

        #region 创建/更新人V1.0
        [ApiMember(Description = "创建人Kvid ")]
        [IgnoreUpdate]
        [CurrentMemberKvid]
        public Guid CreatorKvid { get; set; }

        [ApiMember(Description = "创建人")]
        [IgnoreUpdate]
        [StringLength(50), CurrentMemberName]
        public string CreatorName { get; set; }

        [ApiMember(Description = "更新人Kvid ")]
        [CurrentMemberKvid]
        public Guid UpdaterKvid { get; set; }

        [ApiMember(Description = "更新人")]
        [StringLength(50), CurrentMemberName]
        public string UpdaterName { get; set; }
        #endregion

    }

    public class Location : EntityWithMetadata
    {
        [InternalSetter]
        [DefaultEmptyGuid]
        public Guid OwnerKvid { get; set; }

        [InternalSetter]
        [StringLength(500)]//所属信息，记录当前数据的所属信息，可以是部门可以是组织可以是个人
        public string OwnerName { get; set; }

        [ApiMember(Description = "地点名称")]
        [Required]
        [StringLength(200)]
        public string Title { get; set; }

        [ApiMember(Description = "地点地址")]
        [StringLength(500), Default("")]
        public string Address { get; set; }

        /// <summary>
        /// 内部编码，唯一,样品在流转过程中必须传入目标地点的InternalCode
        /// </summary>
        [ApiMember(Description = "内部编码")]
        [StringLength(200), Required]
        [Unique()]
        public string InternalCode { get; set; }

        [ApiMember(Description = "配置类型")]
        [StringLength(50), Default("")]
        public string Type { get; set; }

        [InternalSetter]
        [DefaultEmptyGuid]
        public Guid ManagerKvid { get; set; }

        [InternalSetter]
        [StringLength(500)]
        public string ManagerName { get; set; }

        #region 文本 摘要 备注
        [ApiMember(Description = "摘要，最大500字")]
        //[IgnoreUpdate]
        [StringLength(500), Default("")]
        public string Summary { get; set; }

        [ApiMember(Description = "备注，最大2000字")]
        [StringLength(2000), Default("")]
        public string Remark { get; set; }
        #endregion
    }

    public class Route : EntityWithMetadata, IEntityHasBiz, IEntityInAssemblyDb, IEntityHasRemark, IEntityHasCreator, IEntityHasUpdater
    {
        [ApiMember(Description = "样品名称")]
        [IgnoreUpdate]
        [StringLength(200), Default("")]
        public string SampleName { get; set; }

        [ApiMember(Description = "样品Kvid")]
        [DefaultEmptyGuid]
        public Guid SampleKvid { get; set; }

        [ApiMember(Description = "主样品Kvid")]
        [DefaultEmptyGuid]
        public Guid SampleRootKvid { get; set; }

        [ApiMember(Description = "父级样品Kvid")]
        [DefaultEmptyGuid]
        public Guid SampleParentKvid { get; set; }

        #region 第三方关联V1.0
        [ApiMember(Description = "关联业务,例如:此样品用于具体某一报告,此处记录报告信息")]
        [InternalSetter]
        [StringLength(200), Default("")]
        public string BizId { get; set; }

        [ApiMember(Description = "业务Kvid")]
        [InternalSetter]
        [DefaultEmptyGuid]
        public Guid BizKvid { get; set; }

        [ApiMember(Description = "业务类型,指实体类型全名称")]
        [InternalSetter]
        [StringLength(200), Default("")]
        public string BizType { get; set; }
        #endregion

        #region 基本信息
        [ApiMember(Description = "样品路由标题")]
        [StringLength(200), Required]
        public string Title { get; set; }

        /// <summary>
        /// 送样，快递等
        /// </summary>
        [ApiMember(Description = "样品路由类型")]
        [StringLength(50)]
        public string Type { get; set; }

        /// <summary>
        /// 当前路由地点
        /// </summary>
        [ApiMember(Description = "当前路由地点")]
        [StringLength(200), Required]
        public string CurrentLocationTitle { get; set; }

        [ApiMember(Description = "当前路由地点Kvid")]
        [DefaultEmptyGuid]
        public Guid CurrentLocationKvid { get; set; }

        /// <summary>
        /// 目标地点,目标节点是下一个节点产生后返写的,代表此样品已经从当前节点离开
        /// </summary>
        [ApiMember(Description = "目标路由地点")]
        [StringLength(200)]
        public string NextLocationTitle { get; set; }

        [ApiMember(Description = "目标路由地点Kvid")]
        [DefaultEmptyGuid]
        public Guid NextLocationKvid { get; set; }

        /// <summary>
        /// 操作人
        /// </summary>
        [ApiMember(Description = "操作人")]
        [StringLength(100), Default("")]
        public string OperatorName { get; set; }

        /// <summary>
        /// 操作人Kvid
        /// </summary>
        [ApiMember(Description = "操作人Kvid")]
        public Guid OperatorKvid { get; set; }

        /// <summary>
        /// 操作日期
        /// </summary>
        [ApiMember(Description = "操作日期")]
        public DateTime OperateTime { get; set; }

        /// <summary>
        /// 摘要
        /// </summary>
        [ApiMember(Description = "摘要")]
        [StringLength(1000), Default("")]
        public string Summary { get; set; }

        [ApiMember(Description = "备注")]
        [StringLength(1000), Default("")]
        public string Remark { get; set; }

        [ApiMember(Description = "创建人Kvid ")]
        [IgnoreUpdate]
        [CurrentMemberKvid]
        public Guid CreatorKvid { get; set; }

        [ApiMember(Description = "创建人")]
        [IgnoreUpdate]
        [StringLength(50), CurrentMemberName]
        public string CreatorName { get; set; }

        [ApiMember(Description = "更新人Kvid ")]
        [CurrentMemberKvid]
        public Guid UpdaterKvid { get; set; }

        [ApiMember(Description = "更新人")]
        [StringLength(50), CurrentMemberName]
        public string UpdaterName { get; set; }
        #endregion
    }

    public class RfidBound : EntityWithMetadata, IEntityInAssemblyDb
    {

        [ApiMember(Description = "Tid")]
        [Required, Unique]
        [StringLength(500)]
        public string Tid { get; set; }

        [ApiMember(Description = "Epc")]
        [StringLength(500)]
        public string Epc { get; set; }
    }

    public enum SampleType
    {
        Unsupport = 0,

        /// <summary>
        /// 主样
        /// </summary>
        Master,

        /// <summary>
        /// 子样
        /// </summary>
        Node,

        /// <summary>
        /// 包裹
        /// </summary>
        Package
    }

    public enum PackageStatus
    {
        /// <summary>
        /// 空闲
        /// </summary>
        Empty = 0,
        /// <summary>
        /// 装箱
        /// </summary>
        Full = 100,
        /// <summary>
        /// 入库
        /// </summary>
        Inbound = 200
    }
}
