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;

/**
 * @Author: zi run
 * @Date 2024/9/20 14:52
 * @Description 数据源实体类
 */
@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.URL, host, port, key))
                .password(DatasourceContent.PASSWORD)
                .userName(DatasourceContent.USERNAME)
                .build();
    }
}
