import * as path from 'path';
import { Logger } from '../utils/logger.js';
import { ConfigManager } from '../utils/configManager.js';
/**
 * Enterprise S3 Integration Module.
 */
export class S3Uploader {
    /**
     * Uploads a local file to AWS S3.
     * Returns the public/private URL.
     */
    static async uploadFile(filePath, metadata = {}) {
        const config = ConfigManager.getInstance().getS3Config();
        const bucket = config.bucket;
        const folder = config.folder;
        const fileName = path.basename(filePath);
        const key = `${folder}/${Date.now()}_${fileName}`;
        Logger.log(`Uploading ${fileName} to S3 bucket ${bucket}...`);
        try {
            // Logic would be:
            // const client = new S3Client({ region: process.env.AWS_REGION });
            // const command = new PutObjectCommand({
            //   Bucket: bucket,
            //   Key: key,
            //   Body: fs.createReadStream(filePath),
            //   ContentType: this.getContentType(fileName)
            // });
            // await client.send(command);
            const url = `https://${bucket}.s3.amazonaws.com/${key}`;
            Logger.log(`Upload successful: ${url}`);
            return {
                url,
                bucket,
                key
            };
        }
        catch (err) {
            Logger.error(`S3 Upload failed for ${filePath}`, err);
            throw err;
        }
    }
    static getContentType(fileName) {
        const ext = path.extname(fileName).toLowerCase();
        const map = {
            '.pdf': 'application/pdf',
            '.csv': 'text/csv',
            '.json': 'application/json',
            '.png': 'image/png',
            '.jpg': 'image/jpeg'
        };
        return map[ext] || 'application/octet-stream';
    }
}
