const moment = require("moment-timezone");
const logger = require("../utils/logger");
const s3Client = require("../utils/s3"); // Using the S3 client utilities with LocalStack support

const emsUpload = async (req, res) => {
    try {
        const { bodyshopid, ciecaid, clm_no, ownr_ln } = req.body;
        const presignedUrl = await s3Client.getPresignedUrl({
            bucketName: process.env.S3_EMS_UPLOAD_BUCKET,
            key: `${bodyshopid}/${ciecaid}-${clm_no}-${ownr_ln}-${moment().format("YYYY-MM-DD--HH-mm-ss")}.zip`
        });
        res.status(200).json({ presignedUrl });
    } catch (error) {
        logger.log("ems-upload-presign-error", "ERROR", req?.user?.email, null, {
            error: error.message,
            stack: error.stack
        });
        res.status(500).json({ error: error.message, stack: error.stack });
    }
};

exports.default = emsUpload;