"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const actions_core_1 = require("@segment/actions-core");
const operations2_1 = require("./operations2");
const action = {
    title: 'Post Sheet V2',
    description: 'Write values to a Google Sheets spreadsheet.',
    defaultSubscription: 'event = "updated" or event = "new"',
    syncMode: {
        description: 'Define how the records from your destination will be synced.',
        label: 'How to sync records',
        default: 'upsert',
        choices: [
            {
                label: 'If a record with the specified identifier is found, it will be updated. If not, a new row will be created.',
                value: 'upsert'
            },
            {
                label: "Add a new record when the specified identifier doesn't exist. If it does, it will be skipped.",
                value: 'add'
            },
            {
                label: "Update a record if a match with the specified identifier is found. Do nothing if the row doesn't exist.",
                value: 'update'
            }
        ]
    },
    fields: {
        record_identifier: {
            label: 'Record Identifier',
            description: 'Property which uniquely identifies each row in the spreadsheet.',
            type: 'string',
            required: true,
            default: { '@path': '$.__segment_id' }
        },
        spreadsheet_id: {
            label: 'Spreadsheet ID',
            description: 'The identifier of the spreadsheet. You can find this value in the URL of the spreadsheet. e.g. https://docs.google.com/spreadsheets/d/{SPREADSHEET_ID}/edit',
            type: 'string',
            required: true,
            default: ''
        },
        spreadsheet_name: {
            label: 'Spreadsheet Name',
            description: 'The name of the spreadsheet. You can find this value on the tab at the bottom of the spreadsheet. Please provide a valid name of a sheet that already exists.',
            type: 'string',
            required: true,
            default: 'Sheet1'
        },
        data_format: {
            label: 'Data Format',
            description: 'The way Google will interpret values. If you select raw, values will not be parsed and will be stored as-is. If you select user entered, values will be parsed as if you typed them into the UI. Numbers will stay as numbers, but strings may be converted to numbers, dates, etc. following the same rules that are applied when entering text into a cell via the Google Sheets UI.',
            type: 'string',
            required: true,
            default: 'RAW',
            choices: [
                { label: 'Raw', value: 'RAW' },
                { label: 'User Entered', value: 'USER_ENTERED' }
            ]
        },
        fields: {
            label: 'Fields',
            description: `
  The fields to write to the spreadsheet.

  On the left-hand side, input the name of the field as it will appear in the Google Sheet.

  On the right-hand side, select the field from your data model that maps to the given field in your sheet.

  ---

  `,
            type: 'object',
            required: true,
            defaultObjectUI: 'keyvalue:only'
        },
        enable_batching: {
            type: 'boolean',
            label: 'Batch Data to Google Sheets',
            description: 'Set as true to ensure Segment sends data to Google Sheets in batches. Please do not set to false.',
            default: true
        },
        batch_size: {
            type: 'number',
            label: 'Batch Size',
            description: 'The number of rows to write to the spreadsheet in a single batch. The value is determined by number of rows * columns that Segment can upload within 30s.',
            default: 1001,
            required: true,
            unsafe_hidden: true
        },
        batch_bytes: {
            type: 'number',
            label: 'Batch Bytes',
            description: 'The number of bytes to write to the spreadsheet in a single batch. Limit is 2MB.',
            default: 2000000,
            required: true,
            unsafe_hidden: true
        }
    },
    perform: (request, { payload, syncMode }) => {
        if (!syncMode) {
            throw new actions_core_1.IntegrationError('Sync mode is required for this action.', 'INVALID_REQUEST_DATA', 400);
        }
        return (0, operations2_1.processData)(request, [payload], syncMode);
    },
    performBatch: (request, { payload, syncMode }) => {
        if (!syncMode) {
            throw new actions_core_1.IntegrationError('Sync mode is required for this action.', 'INVALID_REQUEST_DATA', 400);
        }
        return (0, operations2_1.processData)(request, payload, syncMode);
    }
};
exports.default = action;
//# sourceMappingURL=index.js.map