"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeOutNameWithCustomCredentials = exports.getS3OutputProviderFromCli = exports.S3_OUTPUT_PROVIDER_SECRET_ACCESS_KEY_ENV_NAME = exports.S3_OUTPUT_PROVIDER_ACCESS_KEY_ID_ENV_NAME = void 0;
const lambda_client_1 = require("@remotion/lambda-client");
exports.S3_OUTPUT_PROVIDER_ACCESS_KEY_ID_ENV_NAME = 'REMOTION_S3_OUTPUT_PROVIDER_ACCESS_KEY_ID';
exports.S3_OUTPUT_PROVIDER_SECRET_ACCESS_KEY_ENV_NAME = 'REMOTION_S3_OUTPUT_PROVIDER_SECRET_ACCESS_KEY';
const getS3OutputProviderFromCli = ({ endpoint, region, forcePathStyle, }) => {
    var _a, _b;
    const hasAnyS3OutputProviderFlag = endpoint !== undefined ||
        region !== undefined ||
        forcePathStyle !== undefined;
    if (!hasAnyS3OutputProviderFlag) {
        return null;
    }
    if (!endpoint) {
        throw new Error('Pass --s3-output-provider-endpoint when using S3 output provider flags.');
    }
    return {
        endpoint,
        accessKeyId: (_a = lambda_client_1.LambdaClientInternals.getEnvVariable(exports.S3_OUTPUT_PROVIDER_ACCESS_KEY_ID_ENV_NAME)) !== null && _a !== void 0 ? _a : null,
        secretAccessKey: (_b = lambda_client_1.LambdaClientInternals.getEnvVariable(exports.S3_OUTPUT_PROVIDER_SECRET_ACCESS_KEY_ENV_NAME)) !== null && _b !== void 0 ? _b : null,
        region,
        forcePathStyle,
    };
};
exports.getS3OutputProviderFromCli = getS3OutputProviderFromCli;
const makeOutNameWithCustomCredentials = ({ bucketName, key, s3OutputProvider, }) => {
    if (!s3OutputProvider) {
        return key !== null && key !== void 0 ? key : null;
    }
    if (!bucketName) {
        throw new Error('Pass --force-bucket-name when using S3 output provider flags.');
    }
    if (!key) {
        throw new Error('Pass --out-name when using S3 output provider flags.');
    }
    return {
        bucketName,
        key,
        s3OutputProvider,
    };
};
exports.makeOutNameWithCustomCredentials = makeOutNameWithCustomCredentials;
