"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const sf_properties_1 = require("../sf-properties");
const sf_operations_1 = __importStar(require("../sf-operations"));
const OBJECT_NAME = 'Case';
const action = {
    title: 'Case V2',
    description: 'Create, update, or upsert cases in Salesforce.',
    syncMode: {
        description: 'Define how the records from your destination will be synced.',
        label: 'How to sync records',
        default: 'add',
        choices: [
            { label: 'Insert Records', value: 'add' },
            { label: 'Update Records', value: 'update' },
            { label: 'Upsert Records', value: 'upsert' },
            { label: 'Delete Records. Not available when using batching. Requests will result in errors.', value: 'delete' }
        ]
    },
    fields: {
        recordMatcherOperator: sf_properties_1.recordMatcherOperator2,
        enable_batching: sf_properties_1.enable_batching2,
        batch_size: sf_properties_1.batch_size2,
        traits: sf_properties_1.traits2,
        bulkUpsertExternalId: sf_properties_1.bulkUpsertExternalId2,
        bulkUpdateRecordId: sf_properties_1.bulkUpdateRecordId2,
        description: {
            label: 'Description',
            description: 'A text description of the case.',
            type: 'string',
            depends_on: sf_properties_1.hideIfDeleteSyncMode
        },
        customFields: sf_properties_1.customFields2
    },
    perform: async (request, { settings, payload, syncMode }) => {
        const sf = new sf_operations_1.default(settings.instanceUrl, await (0, sf_operations_1.generateSalesforceRequest)(settings, request));
        if (syncMode === 'add') {
            return await sf.createRecord(payload, OBJECT_NAME);
        }
        (0, sf_properties_1.validateLookup2)(syncMode, payload);
        if (syncMode === 'update') {
            return await sf.updateRecord(payload, OBJECT_NAME);
        }
        if (syncMode === 'upsert') {
            return await sf.upsertRecord(payload, OBJECT_NAME);
        }
        if (syncMode === 'delete') {
            return await sf.deleteRecord(payload, OBJECT_NAME);
        }
    },
    performBatch: async (request, { settings, payload, syncMode, features, statsContext, logger }) => {
        const sf = new sf_operations_1.default(settings.instanceUrl, await (0, sf_operations_1.generateSalesforceRequest)(settings, request));
        let shouldShowAdvancedLogging = false;
        if (features && features['salesforce-advanced-logging']) {
            shouldShowAdvancedLogging = true;
        }
        return sf.bulkHandlerWithSyncMode(payload, OBJECT_NAME, syncMode, {
            shouldLog: shouldShowAdvancedLogging,
            stats: statsContext,
            logger
        });
    }
};
exports.default = action;
//# sourceMappingURL=index.js.map