using OASystem.Domain.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace OASystem.Domain.Entities.Groups
{
    /// <summary>
    /// 团组流程管控
    /// </summary>
    [SugarTable("Grp_Schedule")]
    public class Grp_ScheduleInfo : EntityBase
    {
        /// <summary>
        /// 团组Id
        /// </summary>
        [SugarColumn(IsNullable = true, ColumnDataType = "int")]
        public int DiId { get; set; }

        /// <summary>
        /// 当前主流程
        /// </summary>
        [SugarColumn(IsNullable = true, ColumnDataType = "int")]
        public GrpSchedulePrimaryStepEnum PrimaryStep { get; set; }

        /// <summary>
        /// 当前子流程
        /// </summary>
        //[SugarColumn(IsNullable = true, ColumnDataType = "int")]
        //public int DetailStep { get; set; }

        /// <summary>
        /// 预计开始时间
        /// </summary>
        [SugarColumn(IsNullable = true, ColumnDataType = "datetime")]
        public DateTime ExpectBeginDt { get; set; }

        /// <summary>
        /// 预计结束时间
        /// </summary>
        [SugarColumn(IsNullable = true, ColumnDataType = "datetime")]
        public DateTime ExpectEndDt { get; set; }

        /// <summary>
        /// 实际开始时间
        /// </summary>
        [SugarColumn(IsNullable = true, ColumnDataType = "datetime")]
        public DateTime RealBeginDt { get; set; }

        /// <summary>
        /// 实际结束时间
        /// </summary>
        [SugarColumn(IsNullable = true, ColumnDataType = "datetime")]
        public DateTime RealEndDt { get; set; }

        /// <summary>
        /// 总负责人(SysUser.Id)
        /// </summary>
        [SugarColumn(IsNullable = true, ColumnDataType = "int")]
        public int Leader { get; set; }
        /// <summary>
        /// 异常状态0：正常，1：异常
        /// </summary>
        [SugarColumn(IsNullable = true, ColumnDataType = "int")]
        public int Exception { get; set; }
    }


    /// <summary>
    /// 团组流程管控详细进度
    /// 因为要实现DeepClone 字段必须在同一类下所以不能继承EntityBase
    /// </summary>
    [SugarTable("Grp_ScheduleDetail")]
    [Serializable]
    public class Grp_ScheduleDetailInfo : ICloneable
    {
        /// <summary>
        /// 编号
        /// </summary>
        [SugarColumn(ColumnDescription = "主键", IsPrimaryKey = true, IsIdentity = true, IsNullable = false)]
        public int Id { get; set; }
        /// <summary>
        /// 创建者Id
        /// </summary>
        [SugarColumn(ColumnDescription = "创建者Id", IsNullable = true, ColumnDataType = "int")]
        public int CreateUserId { get; set; }
        /// <summary>
        /// 创建时间
        /// </summary>
        [SugarColumn(ColumnDescription = "创建时间", IsNullable = true, ColumnDataType = "DateTime")]
        public DateTime CreateTime { get; set; } = DateTime.Now;
        /// <summary>
        /// 删除者Id
        /// </summary>
        [SugarColumn(ColumnDescription = "删除者Id", IsNullable = true, ColumnDataType = "int")]
        public int? DeleteUserId { get; set; }
        /// <summary>
        /// 删除时间
        /// </summary>
        [SugarColumn(ColumnDescription = "删除时间", IsNullable = true, ColumnDataType = "varchar(30)")]
        public string DeleteTime { get; set; }
        /// <summary>
        /// 备注
        /// </summary>
        [SugarColumn(IsNullable = true, ColumnDataType = "varchar(500)")]
        public string Remark { get; set; }
        /// <summary>
        /// 是否删除
        /// </summary>
        [SugarColumn(ColumnDescription = "是否删除", IsNullable = true, ColumnDataType = "int")]
        public int IsDel { get; set; }

        /// <summary>
        /// 团组流程Id
        /// </summary>
        [SugarColumn(IsNullable = true, ColumnDataType = "int")]
        public int ScheduleId { get; set; }

        /// <summary>
        /// 等级
        /// </summary>
        [SugarColumn(IsNullable = true, ColumnDataType = "int")]
        public int SLevel { get; set; }

        /// <summary>
        /// 流程
        /// </summary>
        [SugarColumn(IsNullable = true, ColumnDataType = "int")]
        public int Step { get; set; }

        /// <summary>
        /// 父级流程
        /// </summary>
        [SugarColumn(IsNullable = true, ColumnDataType = "int")]
        public int ParentStep { get; set; }

        /// <summary>
        /// 流程状态
        /// <list type="table">
        /// <item><para>0：待分配（未开始）</para></item>
        /// <item><para>1：进行中</para></item>
        /// <item><para>2：已完成</para></item>
        /// </list>
        /// </summary>
        [SugarColumn(IsNullable = true, ColumnDataType = "int")]
        public int StepStatus { get; set; }

        /// <summary>
        /// 负责人员(SysUser.Id)
        /// </summary>
        [SugarColumn(IsNullable = true, ColumnDataType = "int")]
        public int Duty { get; set; }

        /// <summary>
        /// 工作内容
        /// </summary>
        [SugarColumn(IsNullable = true, ColumnDataType = "varchar(50)")]
        public string JobContent { get; set; }

        /// <summary>
        /// 预计开始时间
        /// </summary>
        [SugarColumn(IsNullable = true, ColumnDataType = "datetime")]
        public DateTime ExpectBeginDt { get; set; }

        /// <summary>
        /// 预计结束时间
        /// </summary>
        [SugarColumn(IsNullable = true, ColumnDataType = "datetime")]
        public DateTime ExpectEndDt { get; set; }

        /// <summary>
        /// 实际开始时间
        /// </summary>
        [SugarColumn(IsNullable = true, ColumnDataType = "datetime")]
        public DateTime RealBeginDt { get; set; }

        /// <summary>
        /// 实际结束时间
        /// </summary>
        [SugarColumn(IsNullable = true, ColumnDataType = "datetime")]
        public DateTime RealEndDt { get; set; }

        /// <summary>
        /// 异常状态0：正常，1：异常
        /// </summary>
        [SugarColumn(IsNullable = true, ColumnDataType = "int")]
        public int Exception { get; set; }



        
        public object Clone()
        {
            return this.MemberwiseClone();
        }

        public Grp_ScheduleDetailInfo DeepClone()
        {
            using (Stream objectStream = new MemoryStream())
            {
                IFormatter formatter = new BinaryFormatter();
                formatter.Serialize(objectStream, this);
                objectStream.Seek(0, SeekOrigin.Begin);
                return formatter.Deserialize(objectStream) as Grp_ScheduleDetailInfo;
            }
        }
    }

    /// <summary>
    /// 团组流程管控人员配置
    /// </summary>
    [SugarTable("Grp_SchedulePerson")]
    public class Grp_SchedulePersonInfo : EntityBase
    {
        /// <summary>
        /// 流程Id
        /// </summary>
        [SugarColumn(IsNullable = true, ColumnDataType = "int")]
        public int ScheduleId { get; set; }

        /// <summary>
        /// 人员编号(SysUser.Id)
        /// </summary>
        [SugarColumn(IsNullable = true, ColumnDataType = "int")]
        public int SysUserId { get; set; }

        /// <summary>
        /// 人员姓名
        /// </summary>
        [SugarColumn(IsNullable = true, ColumnDataType = "varchar(50)")]
        public string SysUserName { get; set; }

        /// <summary>
        /// 负责工作
        /// </summary>
        [SugarColumn(IsNullable = true, ColumnDataType = "varchar(50)")]
        public string JobStr { get; set; }

    }
}
