"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ShippingProviderFactory = void 0;
const database_1 = __importDefault(require("../../../config/database"));
const shiprocket_provider_1 = require("../providers/shiprocket.provider");
const manual_provider_1 = require("../providers/manual.provider");
const encryption_utils_1 = require("../../../utils/encryption.utils");
class ShippingProviderFactory {
    static async getProvider(providerName) {
        const name = providerName.toUpperCase();
        // Query credentials configuration from database
        const setting = await database_1.default.shippingProvider.findUnique({
            where: { providerName: name },
        });
        const config = setting
            ? {
                apiEmail: setting.apiEmail || undefined,
                apiPassword: setting.apiPassword ? (0, encryption_utils_1.decrypt)(setting.apiPassword) : undefined,
                apiToken: setting.apiToken ? (0, encryption_utils_1.decrypt)(setting.apiToken) : undefined,
                clientId: setting.clientId || undefined,
                clientSecret: setting.clientSecret ? (0, encryption_utils_1.decrypt)(setting.clientSecret) : undefined,
                apiKey: setting.apiKey || undefined,
                secretKey: setting.secretKey ? (0, encryption_utils_1.decrypt)(setting.secretKey) : undefined,
                environment: setting.environment || 'sandbox',
                warehouseName: setting.warehouseName || undefined,
                pickupLocation: setting.pickupLocation || undefined,
            }
            : {};
        switch (name) {
            case 'SHIPROCKET':
                return new shiprocket_provider_1.ShiprocketProvider(config);
            case 'MANUAL':
                return new manual_provider_1.ManualShippingProvider(config);
            default:
                // Support future channels automatically by defaulting to Manual
                return new manual_provider_1.ManualShippingProvider(config);
        }
    }
}
exports.ShippingProviderFactory = ShippingProviderFactory;
//# sourceMappingURL=shipping-provider.factory.js.map