using Hotline.Settings;
using Hotline.Settings.Hotspots;
using Hotline.Users;
using SqlSugar;
using System.ComponentModel;
using XF.Domain.Repository;
using Hotline.Share.Enums.Planlibrary;
using Hotline.Share.Dtos.File;

namespace Hotline.Planlibrary;

/// <summary>
/// 预案库列表内容
/// </summary>
[Description("预案库列表")]
[SugarIndex("index_planlibrary_hotspotId", nameof(PlanList.HotspotId), OrderByType.Desc)]
[SugarIndex("index_planlibrary_attribution", nameof(PlanList.Attribution), OrderByType.Desc)]
[SugarIndex("index_planlibrary_creatorOrgId", nameof(PlanList.CreatorOrgId), OrderByType.Desc)]
public class PlanList : CreationEntity
{
    /// <summary>
    /// 标题
    /// </summary>
    [SugarColumn(ColumnDescription = "标题")]
    public string Title { get; set; }

    /// <summary>
    /// 关键词
    /// </summary>
    [SugarColumn(ColumnDataType = "json", IsJson = true, IsNullable = true, ColumnDescription = "关键词")]
    public List<string>? Keywords { get; set; }

    /// <summary>
    /// 内容
    /// </summary>
    [SugarColumn(ColumnDataType = "text", ColumnDescription = "内容")]
    public string Content { get; set; }

    /// <summary>
    /// 预案申请状态
    /// </summary>
    [SugarColumn(ColumnDescription = "预案申请状态")]
    public EPlanApplyStatus ApplyStatus { get; set; }

    /// <summary>
    /// 预案状态
    /// </summary>
    [SugarColumn(ColumnDescription = "预案状态")]
    public EPlanStatus Status { get; set; }

    /// <summary>
    /// 预案归属
    /// </summary>
    [SugarColumn(ColumnDescription = "预案归属")]
    public string Attribution { get; set; }

    /// <summary>
    /// 热点
    /// </summary>
    [SugarColumn(ColumnDescription = "热点")]
    public string? HotspotId { get; set; }

    /// <summary>
    /// 外部数据（为前端提供级联功能）
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = "外部数据（为前端提供级联功能）")]
    public string? HotspotExternal { get; set; }

    /// <summary>
    /// 热点
    /// </summary>
    [Navigate(NavigateType.OneToOne, nameof(HotspotId))]//一对一 
    public Hotspot? HotspotType { get; set; }

    /// <summary>
    /// 是否公开
    /// </summary>
    [SugarColumn(ColumnDescription = "是否公开")]
    public bool IsPublic { get; set; }

    /// <summary>
    /// 是否删除
    /// </summary>
    [SugarColumn(ColumnDescription = "是否删除")]
    public bool? IsDeleted { get; set; } = false;

    /// <summary>
    /// 阅读次数
    /// </summary>
    [SugarColumn(ColumnDescription = "阅读次数")]
    public int PageView { get; set; } = 0;

    /// <summary>
    /// 上架时间
    /// </summary>
    [SugarColumn(ColumnDescription = "上架时间")]
    public DateTime? OnShelfTime { get; set; }

    /// <summary>
    /// 下架时间
    /// </summary>
    [SugarColumn(ColumnDescription = "下架时间")]
    public DateTime? OffShelfTime { get; set; }

    /// <summary>
    /// 创建人
    /// </summary>
    [Navigate(NavigateType.OneToOne, nameof(CreatorId))]
    public User? Creator { get; set; }

    /// <summary>
    /// 创建部门
    /// </summary>
    [Navigate(NavigateType.OneToOne, nameof(CreatorOrgId))]//一对一 
    public SystemOrganize? SystemOrganize { get; set; }

    /// <summary>
    /// 更新时间
    /// </summary>
    [SugarColumn(ColumnDescription = "更新时间")]
    public DateTime? UpdateTime { get; set; }

    /// <summary>
    /// 申请理由
    /// </summary>
    [SugarColumn(ColumnDescription = "申请理由")]
    public string? ApplyReason { get; set; }

    /// <summary>
    /// 审核意见
    /// </summary>
    [SugarColumn(ColumnDescription = "审核意见")]
    public string? ExaminOpinion { get; set; }

    /// <summary>
    /// 审核人ID
    /// </summary>
    public string? ExaminManId { get; set; }

    /// <summary>
    /// 审核人
    /// </summary>
    [Navigate(NavigateType.OneToOne, nameof(ExaminManId))]
    public User? ExaminMan { get; set; }

    /// <summary>
    /// 审核部门ID
    /// </summary>
    [SugarColumn(ColumnDescription = "审核部门")]
    public string? ExaminOrganizeId { get; set; }

    /// <summary>
    /// 审核部门
    /// </summary>
    [Navigate(NavigateType.OneToOne, nameof(ExaminOrganizeId))]//一对一 
    public SystemOrganize? ExaminOrganize { get; set; }

    /// <summary>
    /// 审核时间
    /// </summary>
    public DateTime? ExaminTime { get; set; }

    /// <summary>
    /// 失效时间
    /// </summary>
    [SugarColumn(ColumnDescription = "失效时间")]
    public DateTime? ExpiredTime { get; set; }

    /// <summary>
    /// 评分
    /// </summary>
    [SugarColumn(ColumnDescription = "评分")]
    public decimal? Score { get; set; } = decimal.Zero;

    /// <summary>
	/// 预案库类型关联ID
	/// </summary>
	//[Navigate(NavigateType.OneToMany, nameof(PlanRelationType.PlanId))]
    //public List<PlanRelationType> PlanTypes { get; set; }


    [Navigate(typeof(PlanRelationType), nameof(PlanRelationType.PlanId), nameof(PlanRelationType.PlanTypeId))]
    public List<PlanType> PlanTypes { get; set; }


    /// <summary>
    /// 附件
    /// </summary>
    [SugarColumn(ColumnDataType = "json", IsJson = true, IsNullable = true)]
    public List<FileJson>? FileJson { get; set; }
}