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.ModelCompressVo;
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;

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

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

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

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

    /**
     * 源模型。
     */
    private Long sourceVersionId;

    /**
     * 源模型字典。
     */
    @RelationDict(
            masterIdField = "sourceVersionId",
            slaveModelClass = ModelVersion.class,
            slaveIdField = "versionId",
            slaveNameField = "versionName")
    @TableField(exist = false)
    private Map<String, Object> sourceVersionIdDictMap;

    /**
     * 创建方式。
     */
    private Integer createMethod;

    /**
     * 目标模型。
     */
    private Long targetVersionId;

    /**
     * 目标模型字典。
     */
    @RelationDict(
            masterIdField = "targetVersionId",
            slaveModelClass = ModelVersion.class,
            slaveIdField = "versionId",
            slaveNameField = "versionName")
    @TableField(exist = false)
    private Map<String, Object> targetVersionIdDictMap;

    /**
     * 目标模型。
     */
    @TableField(exist = false)
    private Long targetModelId;

    /**
     * 新模型名称。
     */
    @TableField(exist = false)
    private String targetModelName;

    /**
     * 任务状态。
     */
    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 ModelCompressModelMapper extends BaseModelMapper<ModelCompressVo, ModelCompress> {
        /**
         * 转换Vo对象到实体对象。
         *
         * @param modelCompressVo 域对象。
         * @return 实体对象。
         */
        @Mapping(target = "modelTask", expression = "java(mapToBean(modelCompressVo.getModelTask(), com.yice.webadmin.app.model.ModelTask.class))")
        @Override
        ModelCompress toModel(ModelCompressVo modelCompressVo);

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

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