package cn.fateverse.query.entity.vo;

import cn.fateverse.query.entity.Portal;
import cn.fateverse.query.entity.PortalMapping;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import org.springframework.util.ObjectUtils;

import java.util.List;


/**
 * 接口管理表(portal 传送门  接口作为入口 传送到其他类型)对象 portal
 *
 * @author clay
 * @date 2024-04-15
 */
@Data
@ApiModel("接口详细管理表Vo")
public class PortalVo extends SimplePortalVo {

    /**
     * 查询类型
     */
    private Integer queryType;

    /**
     * 是否创建数据适配器
     */
    private Boolean createDataAdapter;

    /**
     * 是否分页
     */
    private Boolean page;

    /**
     * 条件映射
     */
    private List<PortalMapping> mappings;

    /**
     * 数据适配器信息
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private DataAdapterVo dataAdapter;

    public static PortalVo toPortalVo(Portal portal) {
        return toPortalVo(portal, null);
    }

    public static PortalVo toPortalVo(Portal portal, List<PortalMapping> mappings) {
        SimplePortalVo simplePortalVo = SimplePortalVo.toPortalVo(portal);
        PortalVo portalVo = new PortalVo();
        BeanUtils.copyProperties(simplePortalVo, portalVo);
        portalVo.setCreateDataAdapter(portal.getCreateDataAdapter());
        if (!ObjectUtils.isEmpty(mappings)) {
            portalVo.setMappings(mappings);
        }
        return portalVo;
    }

}