import { Client } from "minio";

const globalForMinio = globalThis as unknown as {
  minioClient: Client | undefined;
};

export const minioClient =
  globalForMinio.minioClient ??
  new Client({
    endPoint: process.env.MINIO_ENDPOINT || "localhost",
    port: parseInt(process.env.MINIO_PORT || "9000"),
    useSSL: process.env.MINIO_USE_SSL === "true",
    accessKey: process.env.MINIO_ACCESS_KEY || "",
    secretKey: process.env.MINIO_SECRET_KEY || "",
  });

if (process.env.NODE_ENV !== "production")
  globalForMinio.minioClient = minioClient;

export const MINIO_BUCKET_NAME = process.env.MINIO_BUCKET_NAME || "tools";
