package com.muyu.cloud.common.many.datasource.domain.model;

import com.muyu.cloud.common.many.datasource.constents.DatasourceContent;
import com.muyu.cloud.common.saas.domain.model.EntInfo;
import com.muyu.common.core.utils.StringUtils;
import com.muyu.common.system.domain.SysFirmDatasource;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author DongZl
 * @description: 数据源实体类
 * @Date 2023-8-1 上午 11:15
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class DataSourceInfo {

    /**
     * 键
     */
    private String key;

    /**
     * 地址
     */
    private String url;

    /**
     * 用户名
     */
    private String userName;

    /**
     * 密码
     */
    private String password;


    public static DataSourceInfo hostAndPortBuild(EntInfo entInfo) {
        return DataSourceInfo.builder()
                .key(entInfo.getEntCode())
                .url(StringUtils.format(entInfo.getUrl(), entInfo.getIp(), entInfo.getPort(), entInfo.getEntCode()))
                .password(entInfo.getUsername())
                .userName(entInfo.getPassword())
                .build();
    }
}
