package com.yice.webadmin.app.model;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.yice.common.core.annotation.RelationDict;
import com.yice.common.core.annotation.RelationOneToOne;
import com.yice.common.core.base.mapper.BaseModelMapper;
import com.yice.common.core.base.model.BaseModel;
import com.yice.common.core.util.MyCommonUtil;
import com.yice.webadmin.app.vo.ModelEstimateVo;
import com.yice.webadmin.upms.model.SysUser;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.util.Map;

/**
 * ModelEstimate实体对象。
 *
 * @author linking
 * @date 2023-04-13
 */
@Data
@EqualsAndHashCode(callSuper = true)
@TableName(value = "lmp_model_estimate")
public class ModelEstimate extends BaseModel {

    /**
     * 任务ID。
     */
    @TableId(value = "task_id")
    private Long taskId;

    /**
     * 任务名称。
     */
    private String taskName;

    /**
     * 描述。
     */
    private String taskDescribe;

    /**
     * 待评估模型版本ID。
     */
    private Long modelVersionId;
    /**
     * 评估模型版本字典。
     */
    @RelationDict(
            masterIdField = "modelVersionId",
            slaveModelClass = ModelVersion.class,
            slaveIdField = "versionId",
            slaveNameField = "versionName")
    @TableField(exist = false)
    private Map<String, Object> modelVersionIdDictMap;

    /**
     * 评估数据集版本ID。
     */
    private Long datasetVersionId;

    /**
     * 评估数据集版本字典。
     */
    @RelationDict(
            masterIdField = "datasetVersionId",
            slaveModelClass = DatasetVersion.class,
            slaveIdField = "versionId",
            slaveNameField = "versionName")
    @TableField(exist = false)
    private Map<String, Object> datasetVersionIdDictMap;

    /**
     * 打分模式。
     */
    private Integer scoringMode;
    /**
     * 参数配置。
     */
    private String configuration;
    /**
     * 任务状态。
     */
    private Integer taskStatus;
    /**
     * task_name LIKE搜索字符串。
     */
    @TableField(exist = false)
    private String searchString;

    /**
     * 创建人名称字典。
     */
    @RelationDict(
            masterIdField = "createUserId",
            slaveModelClass = SysUser.class,
            slaveIdField = "userId",
            slaveNameField = "showName")
    @TableField(exist = false)
    private Map<String, Object> createUserIdDictMap;

    public void setSearchString(String searchString) {
        this.searchString = MyCommonUtil.replaceSqlWildcard(searchString);
    }

    @RelationOneToOne(
            masterIdField = "taskId",
            slaveModelClass = ModelTask.class,
            slaveIdField = "taskId")
    @TableField(exist = false)
    private ModelTask modelTask;

    @Mapper
    public interface ModelEstimateModelMapper extends BaseModelMapper<ModelEstimateVo, ModelEstimate> {
        /**
         * 转换Vo对象到实体对象。
         *
         * @param modelEstimateVo 域对象。
         * @return 实体对象。
         */
        @Mapping(target = "modelTask", expression = "java(mapToBean(modelEstimateVo.getModelTask(), com.yice.webadmin.app.model.ModelTask.class))")
        @Override
        ModelEstimate toModel(ModelEstimateVo modelEstimateVo);

        /**
         * 转换实体对象到VO对象。
         *
         * @param modelEstimate 实体对象。
         * @return 域对象。
         */
        @Mapping(target = "modelTask", expression = "java(beanToMap(modelEstimate.getModelTask(), false))")
        @Override
        ModelEstimateVo fromModel(ModelEstimate modelEstimate);
    }

    public static final ModelEstimateModelMapper INSTANCE = Mappers.getMapper(ModelEstimateModelMapper.class);
}
