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

import com.muyu.cloud.common.many.datasource.constents.DatasourceContent;
import com.muyu.common.core.utils.StringUtils;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @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(String key, String host, Integer port) {
        return DataSourceInfo.builder()
                .key(key)
                .url(StringUtils.format(DatasourceContent.DATASOURCE_URL, host, port, key))
                .password(DatasourceContent.PASSWORD)
                .userName(DatasourceContent.USER_NAME)
                .build();
    }
}
