package com.microservices.zone.resource.domain.vo;

import com.alibaba.fastjson2.JSONObject;
import com.microservices.common.core.utils.StringUtils;
import com.microservices.common.core.utils.bean.BeanUtils;
import com.microservices.zone.resource.enums.AiResourceCategory;
import com.microservices.zone.resource.utils.ResourceExtendDataUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 * Skill提报输入VO
 */
@Data
@ApiModel("Skill提报输入")
public class AiSkillInputVo {

    @ApiModelProperty(value = "Skill名称", required = true)
    @NotBlank(message = "Skill名称不能为空")
    @Size(max = 100, message = "Skill名称不能超过100个字符")
    private String name;
    @ApiModelProperty(value = "资源领域Id", required = true)
    @NotNull
    private Long domainId;

    @ApiModelProperty(value = "Skill简介")
//    @Size(max = 500, message = "Skill简介不能超过500个字符")
    private String summary;

    @ApiModelProperty(value = "资源标签，逗号分隔")
    private String keywords;

    @ApiModelProperty(value = "Skill文件Id")
    private Long fileId;

    @ApiModelProperty(value = "SKILL.md内容", required = true)
    @NotBlank(message = "SKILL.md内容不能为空")
    private String skillContent;

    @ApiModelProperty(value = "目录树JSON")
    private String fileTreeJson;
    @ApiModelProperty(value = "所属专区", required = true)
    @NotNull
    private Long zoneId;

    public ZoneResourceInputVo toZoneResourceInputVo() {
        ZoneResourceInputVo target = new ZoneResourceInputVo();
        BeanUtils.copyProperties(this, target, "skillContent", "fileTreeJson");
        target.setFileIds(String.valueOf(fileId));

        // 将 Skill 特有字段存入 extendData（JSONObject）
        JSONObject fileTreeJsonObj = StringUtils.isEmpty(fileTreeJson)
                ? null
                : JSONObject.parseObject(fileTreeJson);
        JSONObject extendData = ResourceExtendDataUtils.buildSkillExtendData(
                skillContent, fileTreeJsonObj);
        target.setExtendData(extendData.toJSONString());
        target.setResourceCategory(AiResourceCategory.SKILL.getCode());
        return target;
    }
}
