using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL
{
    public abstract class BaseFullAuditEntity
    {
        [Key]
        public Guid Id { get; set; }
        public Guid CreateUserId { get; set; }
        public DateTime CreateTime { get; set; }
        public Guid UpdateUserId { get; set; }
        public DateTime UpdateTime { get; set; }
    }

    [Table("TrialImageDownload")]
    public class TrialImageDownload : BaseFullAuditEntity
    {
        public Guid SubjectVisitId { get; set; }

        public bool IsSuccess { get; set; }

        public DateTime DownloadStartTime { get; set; }
        public DateTime? DownloadEndTime { get; set; }

        public ImageType ImageType { get; set; }

        public int ImageCount { get; set; }

        public long ImageSize { get; set; }

        #region 测试导航属性

        public List<TestNew> TestNewList { get; set; }

        #endregion
    }

    public enum ImageType
    {
        Dicom = 1,
        NoneDIcom = 2
    };

    public class TestNew : BaseFullAuditEntity
    {
        public Guid TrialImageDownloadId { get; set; }

        public string TestName { get; set; }
    }


    //public class Subject : BaseFullAuditEntity
    //{
    //    public string Name { get; set; }


    //    public Guid? LatestSubjectVisitId { get; set; }

    //    public Guid? FinalSubjectVisitId { get; set; }

    //    #region 同时配置一对多，一对一  导航属性

    //    [ForeignKey("FinalSubjectVisitId")]
    //    public SubejectVisit FinalSubjectVisit { get; set; }

    //    [ForeignKey("LatestSubjectVisitId")]
    //    public SubejectVisit LatestSubjectVisit { get; set; }

    //    public List<SubejectVisit> SubejectVisitList { get; set; }
    //    #endregion

    //}

    //public class SubejectVisit : BaseFullAuditEntity
    //{
    //    public Subject Subject { get; set; }

    //    public Guid SubjectId { get; set; }

    //}


    //public class Dictionary : BaseFullAuditEntity
    //{
    //    #region 导航属性
    //    [ForeignKey("ConfigTypeId")]
    //    public Dictionary ConfigType { get; set; }

    //    [ForeignKey("ParentId")]
    //    public Dictionary Parent { get; set; }

    //    public List<Dictionary> ChildList { get; set; } = new List<Dictionary>();

    //    #endregion


    //    public Guid? ParentId { get; set; }


    //    public Guid? ConfigTypeId { get; set; }

    //    public string Code { get; set; }
    //}

    #region 一个外键 关联两个实体
    //public class ReadingClinicalData : BaseFullAuditEntity
    //{
    //    public string Code { get; set; }


    //    public Guid ReadingId { get; set; }


    //    [ForeignKey("ReadingId")]

    //    public SubejectVisit SubjectVisit { get; set; }

    //    [ForeignKey("ReadingId")]

    //    public ReadModule ReadModule { get; set; }
    //}

    //public class ReadModule : BaseFullAuditEntity
    //{
    //    public string Name { get; set; }
    //}
    #endregion

    #region 测试 字符串默认长度配置

    public class TestStringLength : BaseFullAuditEntity
    {
        public string DefaultLength { get; set; }

        public string UserDefineLength { get; set; }

        public string UserDefineText { get; set; }

    }
    #endregion

    #region 测试生成迁移移除外键约束

    #endregion

    #region 测试迁移不生成外键约束，ef知道外键关系，但是数据库不保存外键
    public class Project : BaseFullAuditEntity
    {

    }

    public class ProjectUser : BaseFullAuditEntity
    {

        public string Code { get; set; }

        public string Name { get; set; }

        //外键
        public Guid ProjectId { get; set; }

        public Project Project { get; set; }
    }

    public class ProjectUser2 : BaseFullAuditEntity
    {
        //外键
        public Guid ProjectId { get; set; }

        public Project Project { get; set; }

        [Comment("NewCreateName")]
        public string NewCreateName { get; set; }

    }
    #endregion

    #region 测试字符串长度

    [Comment("test commment4")]
    public class TestStr: BaseFullAuditEntity
    {
        [Comment("test commment3")]
        public string DefualtLength { get; set; }

        [Comment("test commment1")]
        [MaxLength]
        public string MaxLength { get; set; }

        [Comment("test commment2")]
        [StringLength(400)]
        public string DefineLength { get; set;}

    }

    /// <summary>
    /// 备注
    /// </summary>
    public class TestStr2
    {
        /// <summary>
        /// 备注1
        /// </summary>
        [StringLength(200)]
        public string DefualtLength { get; set; }

        /// <summary>
        /// 备注1
        /// </summary>
        [MaxLength]
        public string MaxLength { get; set; }

        /// <summary>
        /// 备注3
        /// </summary>
        [StringLength(400)]
        public string DefineLength { get; set; }
    }
    #endregion



    #region 测试命名不符合规则

    public class TestFieldName : BaseFullAuditEntity
    {
        public string NAME1 { get; set; }

        public string NAme2 { get; set; }

        public string naMe3 { get; set; }
    }
    #endregion

    #region 测试备注迁移 以及修改备注迁移

    [Comment("这是类备注的修改")]
    public class TestComment: BaseFullAuditEntity
    {
        public string Code { get; set; }

        [Comment("这是字段备注Name的修改")]
        public string Name { get; set; }
    }
    #endregion


    #region 测试默认值约束


    public class TestStrDefaultValue : BaseFullAuditEntity
    {
        //手动不给默认值
        public string Value1 { get; set; }

        //手动给默认值
        public string Value2 { get; set; } = string.Empty;

        //dbfirst 默认生成方式 项目开启了<Nullable>enable</Nullable>
        public string Value3 { get; set; } = null!;
    }
    #endregion
}
