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

import com.alibaba.fastjson2.JSONObject;
import com.microservices.zone.resource.domain.ZoneResource;
import com.microservices.zone.resource.utils.ResourceExtendDataUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

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

/**
 * 模型修改输入VO
 */
@Data
@ApiModel("模型修改输入")
public class AiModelUpdateVo {

    @ApiModelProperty(value = "资源Id", required = true)
    @NotNull(message = "资源Id不能为空")
    private Long id;

    @ApiModelProperty(value = "模型名称")
    @Size(max = 100, message = "模型名称不能超过100个字符")
    private String name;

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

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

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

    @ApiModelProperty(value = "资源领域Id")
    private Long domainId;

    @ApiModelProperty(value = "README.md内容")
    private String readmeContent;

    public ZoneResourceUpdateVo toZoneResourceUpdateVo(ZoneResource existing){
        ZoneResourceUpdateVo zoneResourceUpdateVo = new ZoneResourceUpdateVo();
        zoneResourceUpdateVo.setId(this.getId());
        zoneResourceUpdateVo.setName(this.getName());
        zoneResourceUpdateVo.setSummary(this.getSummary());
        zoneResourceUpdateVo.setKeywords(this.getKeywords());
        zoneResourceUpdateVo.setDomainId(this.getDomainId());

        if (readmeContent != null) {
            JSONObject extendData = existing.getExtendData();
            if (extendData == null) {
                extendData = new JSONObject();
            }
            extendData = ResourceExtendDataUtils.updateModelOrDatasetReadmeContent(existing.getResourceCategory(), extendData, readmeContent);
            zoneResourceUpdateVo.setExtendData(extendData.toJSONString());
        }

        return zoneResourceUpdateVo;
    }
}
