import { registerAs } from '@nestjs/config';

export interface MinioConfig {
  endpoint: string;
  port: number;
  accessKey: string;
  secretKey: string;
  useSSL: boolean;
  region: string;
  bucketDocuments: string;
  bucketArchives: string;
}

export default registerAs('minio', (): MinioConfig => {
  const accessKey = process.env.MINIO_ACCESS_KEY || 'minioadmin';
  const secretKey = process.env.MINIO_SECRET_KEY || 'minioadmin_secret_change_this';

  if (accessKey === 'minioadmin' || secretKey === 'minioadmin_secret_change_this') {
    console.warn(
      'Warning: MinIO credentials are using default values. Change these in production!',
    );
  }

  return {
    endpoint: process.env.MINIO_ENDPOINT || 'localhost',
    port: parseInt(process.env.MINIO_PORT || '9000', 10),
    accessKey,
    secretKey,
    useSSL: process.env.MINIO_USE_SSL === 'true',
    region: process.env.MINIO_REGION || 'us-east-1',
    bucketDocuments: process.env.MINIO_BUCKET_DOCUMENTS || 'goa-gel-documents',
    bucketArchives: process.env.MINIO_BUCKET_ARCHIVES || 'goa-gel-archives',
  };
});
