using System.ComponentModel.DataAnnotations;
using System.Text.Json;
using Tiku.Application.Catalog;
using Tiku.Domain.Catalog;
using Tiku.Domain.Common;
using Tiku.Domain.Content;

namespace Tiku.Api.Contracts;

/// <summary>
/// 创建分类节点请求 DTO。
/// </summary>
public sealed class CreateTaxonomyNodeDto
{
    /// <summary>
    /// 父节点 ID。
    /// </summary>
    public Guid? ParentId { get; set; }
    /// <summary>
    /// 父级来源。
    /// </summary>
    public QuestionSource? ParentSource { get; set; }
    /// <summary>
    /// 节点Type。
    /// </summary>
    [Required]
    public TaxonomyNodeType NodeType { get; set; }
    /// <summary>
    /// 编码。
    /// </summary>
    [Required, StringLength(100)]
    public string Code { get; set; } = string.Empty;
    /// <summary>
    /// 名称。
    /// </summary>
    [Required, StringLength(300)]
    public string Name { get; set; } = string.Empty;
    /// <summary>
    /// 排序值。
    /// </summary>
    public int SortOrder { get; set; }
    /// <summary>
    /// 扩展元数据。
    /// </summary>
    public JsonElement Metadata { get; set; } = JsonDefaults.Object();

    public CreateTaxonomyNodeCommand ToCommand() => new(
        ParentId,
        ParentSource,
        NodeType,
        Code,
        Name,
        SortOrder,
        Metadata);
}
