"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPresignedDownloadUrl = exports.getPresignedUploadUrl = exports.s3Client = exports.s3BucketName = void 0;
const client_s3_1 = require("@aws-sdk/client-s3");
const s3_request_presigner_1 = require("@aws-sdk/s3-request-presigner");
const logger_1 = require("./logger");
const region = process.env.AWS_REGION || 'ap-south-1';
const accessKeyId = process.env.AWS_ACCESS_KEY_ID || 'mock_access_key';
const secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY || 'mock_secret_key';
exports.s3BucketName = process.env.AWS_S3_BUCKET_NAME || 'indian-books-worldwide-bucket';
exports.s3Client = new client_s3_1.S3Client({
    region,
    credentials: {
        accessKeyId,
        secretAccessKey,
    },
});
const getPresignedUploadUrl = async (fileKey, contentType, expiresInSeconds = 3600) => {
    try {
        const command = new client_s3_1.PutObjectCommand({
            Bucket: exports.s3BucketName,
            Key: fileKey,
            ContentType: contentType,
        });
        return await (0, s3_request_presigner_1.getSignedUrl)(exports.s3Client, command, { expiresIn: expiresInSeconds });
    }
    catch (error) {
        logger_1.logger.error(`Failed to generate S3 presigned upload URL: ${error.message}`);
        throw error;
    }
};
exports.getPresignedUploadUrl = getPresignedUploadUrl;
const getPresignedDownloadUrl = async (fileKey, expiresInSeconds = 3600) => {
    try {
        const command = new client_s3_1.GetObjectCommand({
            Bucket: exports.s3BucketName,
            Key: fileKey,
        });
        return await (0, s3_request_presigner_1.getSignedUrl)(exports.s3Client, command, { expiresIn: expiresInSeconds });
    }
    catch (error) {
        logger_1.logger.error(`Failed to generate S3 presigned download URL: ${error.message}`);
        throw error;
    }
};
exports.getPresignedDownloadUrl = getPresignedDownloadUrl;
//# sourceMappingURL=s3.js.map