package org.apache.seatunnel.datasource.plugin.s3;

import io.minio.MinioClient;
import io.minio.errors.MinioException;

public class S3ClientService {
    private String ENDPOINT;
    private String PROVIDER;
    private String USERNAME;
    private String PASSWORD;
    private String BUCKET;

    private Integer PORT;

    private final String clientId = "Client" + (int) (Math.random() * 100000000);
    private MinioClient minioClient;

    public S3ClientService(
            String endpoint,
            String provider,
            String username,
            String password,
            Integer port,
            String bucket)
            throws MinioException {
        this.ENDPOINT = endpoint;
        this.PROVIDER = provider;
        this.USERNAME = username;
        this.PASSWORD = password;
        this.PORT = port;
        this.BUCKET = bucket;
        setMinioClient(endpoint, provider, username, password, port);
    }

    public MinioClient getMinioClient() {
        return minioClient;
    }

    public void setMinioClient(
            String endpoint, String provider, String username, String password, Integer port)
            throws MinioException {
        minioClient =
                new MinioClient.Builder()
                        .endpoint(endpoint, port, false)
                        .credentials(username, password)
                        .build();
    }
}
