package cn.fateverse.query.entity.vo;


import cn.fateverse.query.entity.DataSourceManage;
import cn.fateverse.query.enums.DynamicSourceEnum;
import cn.fateverse.common.core.annotaion.Excel;
import com.alibaba.fastjson2.JSONObject;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 数据源管理对象 query_data_source
 *
 * @author clay
 * @date 2023-07-16
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ApiModel("数据源管理Vo")
public class DataSourceManageVo {

    /**
     * 主键
     */
    @ApiModelProperty("主键")
    private Long id;

    /**
     * 数据源名称
     */
    @ApiModelProperty("数据源名称")
    @Excel("数据源名称")
    private String dsName;

    /**
     * 数据源密码
     */
    @ApiModelProperty("数据源用户名称")
    @Excel("数据源用户名称")
    private String username;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String args;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    private JSONObject params;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String host;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Long port;

    /**
     * 数据源类型,匹配java枚举
     */
    @ApiModelProperty("数据源类型,匹配java枚举")
    @Excel("数据源类型,匹配java枚举")
    private DynamicSourceEnum type;

    /**
     * 数据库名称
     */
    @ApiModelProperty("数据库名称")
    @Excel("数据库名称")
    private String dbName;

    /**
     * 数据源类型
     */
    @ApiModelProperty("数据源类型")
    @Excel("数据源类型")
    private Integer configType;

    /**
     * 数据源连接类型
     */
    @ApiModelProperty("数据源连接类型")
    @Excel("数据源连接类型")
    private String url;

    public static DataSourceManageVo toQueryDataSourceVo(DataSourceManage dataSourceManage) {
        return DataSourceManageVo.builder()
                .id(dataSourceManage.getId())
                .dsName(dataSourceManage.getDsName())
                .username(dataSourceManage.getUsername())
                .type(dataSourceManage.getType())
                .dbName(dataSourceManage.getDbName())
                .configType(dataSourceManage.getConfigType())
                .url(dataSourceManage.getUrl())
                .build();
    }
}