using Furion.DatabaseAccessor;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace YBEE.EQM.Core;

/// <summary>
/// 机构
/// </summary>
[Comment("机构")]
public partial class SysOrg : DEntityBase<short>, IEntityTypeBuilder<SysOrg>
{
    /// <summary>
    /// 父机构ID
    /// </summary>
    [Comment("父机构ID")]
    [Required]
    public short Pid { get; set; } = 0;
    /// <summary>
    /// 父机构ID路径
    /// </summary>
    [Comment("父机构ID路径")]
    [StringLength(200)]
    public string Pids { get; set; } = "[0]";
    /// <summary>
    /// 机构类型
    /// </summary>
    [Comment("机构类型")]
    [Required, Column(TypeName = "smallint")]
    public OrgType OrgType { get; set; } = OrgType.SCHOOL;
    /// <summary>
    /// 办学性质
    /// </summary>
    [Comment("办学性质")]
    [Required, Column(TypeName = "smallint")]
    public OrgFundSource OrgFundSource { get; set; } = OrgFundSource.PUBLIC;
    /// <summary>
    /// 学段
    /// </summary>
    [Comment("学段")]
    [Required, Column(TypeName = "smallint")]
    public EducationStage EducationStage { get; set; } = EducationStage.NONE;
    /// <summary>
    /// 城乡类型
    /// </summary>
    [Comment("城乡类型")]
    [Required, Column(TypeName = "smallint")]
    public UrbanRuralType UrbanRuralType { get; set; } = UrbanRuralType.URBAN;
    /// <summary>
    /// 所属学区ID（机构ID）
    /// </summary>
    [Comment("所属学区ID（机构ID）")]
    public short? SchoolDistrictId { get; set; }
    /// <summary>
    /// 名称
    /// </summary>
    [Comment("名称")]
    [Required, StringLength(100)]
    public string Name { get; set; }
    /// <summary>
    /// 名称
    /// </summary>
    [Comment("名称")]
    [Required, StringLength(200)]
    public string FullName { get; set; }
    /// <summary>
    /// 简称
    /// </summary>
    [Comment("简称")]
    [Required, StringLength(50)]
    public string ShortName { get; set; }
    /// <summary>
    /// 简称2
    /// </summary>
    [Comment("简称2")]
    [StringLength(50)]
    public string ShortName2 { get; set; } = "";
    /// <summary>
    /// 编码
    /// </summary>
    [Comment("编码")]
    [Required, StringLength(20)]
    public string Code { get; set; }
    /// <summary>
    /// 带前缀唯一代码
    /// </summary>
    [Comment("带前缀唯一代码")]
    [Required, StringLength(20)]
    public string UniqueCode { get; set; }
    /// <summary>
    /// TQES学校ID（兼容老系统）
    /// </summary>
    [Comment("TQES学校ID（兼容老系统）")]
    [StringLength(20)]
    public int? TqesId { get; set; }
    /// <summary>
    /// TQES学校编码（兼容老系统）
    /// </summary>
    [Comment("TQES学校编码（兼容老系统）")]
    [StringLength(20)]
    public string TqesCode { get; set; } = "";
    /// <summary>
    /// 排序
    /// </summary>
    [Description("排序")]
    [Required]
    public int Sort { get; set; } = 0;
    /// <summary>
    /// 经度
    /// </summary>
    [Comment("经度")]
    public decimal Longitude { get; set; } = 0;
    /// <summary>
    /// 纬度
    /// </summary>
    [Comment("纬度")]
    public decimal Latitude { get; set; } = 0;
    /// <summary>
    /// 地址
    /// </summary>
    [Comment("地址")]
    public string Address { get; set; } = "";
    /// <summary>
    /// 备注
    /// </summary>
    [Comment("备注")]
    [StringLength(200)]
    public string Remark { get; set; } = "";
    /// <summary>
    /// 状态
    /// </summary>
    [Comment("状态")]
    [Required, Column(TypeName = "smallint")]
    public CommonStatus Status { get; set; } = CommonStatus.ENABLE;

    /// <summary>
    /// 一对一引用（所属学区，即机构）
    /// </summary>
    public virtual SysOrg SchoolDistrict { get; set; }

    public void Configure(EntityTypeBuilder<SysOrg> entityBuilder, DbContext dbContext, Type dbContextLocator)
    {
        entityBuilder.Ignore(t => t.CreateSysUser).Ignore(t => t.UpdateSysUser);
    }
}
