using QYZH.InteractiveMagazine.Common.Helpers;
using QYZH.InteractiveMagazine.Models.Enum;

namespace QYZH.InteractiveMagazine.Models.Dto.Material;

/// <summary>
/// 资料创建/更新输入
/// </summary>
public class MaterialInput
{
    /// <summary>
    /// 资料标题
    /// </summary>
    public string Title { get; set; } = string.Empty;

    /// <summary>
    /// 资料名称
    /// </summary>
    public string? Name { get; set; }

    /// <summary>
    /// 资料描述
    /// </summary>
    public string? Description { get; set; }

    /// <summary>
    /// 排序值，越小越靠前
    /// </summary>
    public int Sort { get; set; }

    /// <summary>
    /// 生效开始时间
    /// </summary>
    public DateTime? StartTime { get; set; }

    /// <summary>
    /// 生效结束时间
    /// </summary>
    public DateTime? EndTime { get; set; }

    /// <summary>
    /// 资料文件列表
    /// </summary>
    public List<MaterialFileInput> Files { get; set; } = new();
}

/// <summary>
/// 资料文件输入
/// </summary>
public class MaterialFileInput
{
    /// <summary>
    /// 文件类型
    /// </summary>
    public MaterialFileTypeEnum FileType { get; set; }

    /// <summary>
    /// 文件OSS路径
    /// </summary>
    public string FileUrl { get; set; } = string.Empty;

    /// <summary>
    /// 文件名称
    /// </summary>
    public string? FileName { get; set; }

    /// <summary>
    /// 排序值，越小越靠前
    /// </summary>
    public int Sort { get; set; }
}

/// <summary>
/// 资料输出
/// </summary>
public class MaterialOutput
{
    /// <summary>
    /// 主键ID
    /// </summary>
    public long Id { get; set; }

    /// <summary>
    /// 资料标题
    /// </summary>
    public string Title { get; set; } = string.Empty;

    /// <summary>
    /// 资料名称
    /// </summary>
    public string? Name { get; set; }

    /// <summary>
    /// 资料描述
    /// </summary>
    public string? Description { get; set; }

    /// <summary>
    /// 排序值，越小越靠前
    /// </summary>
    public int Sort { get; set; }

    /// <summary>
    /// 生效开始时间
    /// </summary>
    public DateTime? StartTime { get; set; }

    /// <summary>
    /// 生效结束时间
    /// </summary>
    public DateTime? EndTime { get; set; }

    /// <summary>
    /// 状态
    /// </summary>
    public int Status { get; set; }

    /// <summary>
    /// 创建人
    /// </summary>
    public string? CreatedBy { get; set; }

    /// <summary>
    /// 创建时间
    /// </summary>
    public DateTime CreatedAt { get; set; }

    /// <summary>
    /// 修改人
    /// </summary>
    public string? UpdatedBy { get; set; }

    /// <summary>
    /// 修改时间
    /// </summary>
    public DateTime? UpdatedAt { get; set; }

    /// <summary>
    /// 资料文件列表
    /// </summary>
    public List<MaterialFileOutput> Files { get; set; } = new();
}

/// <summary>
/// 资料文件输出
/// </summary>
public class MaterialFileOutput
{
    private string _fileUrl = string.Empty;

    /// <summary>
    /// 主键ID
    /// </summary>
    public long Id { get; set; }

    /// <summary>
    /// 文件类型
    /// </summary>
    public MaterialFileTypeEnum FileType { get; set; }

    /// <summary>
    /// 文件完整地址
    /// </summary>
    public string FileUrl
    {
        get => DomainHelper.OssFullUrl(_fileUrl);
        set => _fileUrl = value ?? string.Empty;
    }

    /// <summary>
    /// 文件名称
    /// </summary>
    public string? FileName { get; set; }

    /// <summary>
    /// 排序值，越小越靠前
    /// </summary>
    public int Sort { get; set; }
}

/// <summary>
/// 资料分页查询输入
/// </summary>
public class MaterialQueryInput : PageQueryModel
{
    /// <summary>
    /// 标题
    /// </summary>
    public string? Title { get; set; }

    /// <summary>
    /// 名称
    /// </summary>
    public string? Name { get; set; }

    /// <summary>
    /// 状态
    /// </summary>
    public int? Status { get; set; }
}
