"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const common_fields_1 = require("../common-fields");
const utils_1 = require("../utils");
const action = {
    title: 'Identify',
    description: 'Identify a user in Accoil',
    defaultSubscription: 'type = "identify"',
    fields: {
        userId: {
            type: 'string',
            description: 'The ID associated with the user',
            label: 'User ID',
            required: true,
            default: { '@path': '$.userId' }
        },
        email: {
            type: 'string',
            format: 'email',
            description: 'Email addresses are highly recommended as they are often used to identify users across multiple platforms. (Highly Recommended)',
            label: 'Email',
            default: { '@path': '$.traits.email' }
        },
        name: {
            type: 'string',
            label: 'Name',
            description: 'Providing a name helps display users in Accoil. If no name is provided, the email address is displayed instead. (Highly Recommended)',
            default: { '@path': '$.traits.name' }
        },
        role: {
            type: 'string',
            label: 'Role',
            description: "Describes the user's role in your product such as Admin, Owner, Team Member. (Suggested) ",
            default: { '@path': '$.traits.role' }
        },
        accountStatus: {
            type: 'string',
            label: 'Account Status',
            description: 'Capturing the account status on the user can be helpful to segment users. Possible options include: Free, Trial, Paid, Cancelled (Suggested) ',
            default: { '@path': '$.traits.accountStatus' }
        },
        createdAt: {
            type: 'string',
            format: 'date-time',
            label: 'Created at',
            description: 'When was the user created, including this ensures that tenure tracking is accurate. (Highly Recommended) ',
            default: { '@path': '$.traits.createdAt' }
        },
        traits: common_fields_1.commonFields.traits,
        timestamp: common_fields_1.commonFields.timestamp
    },
    perform: (request, { payload, settings }) => {
        const traits = {
            ...(payload.traits ?? {}),
            email: payload.email,
            name: payload.name,
            role: payload.role,
            createdAt: payload.createdAt,
            accountStatus: payload.accountStatus
        };
        return request((0, utils_1.endpointUrl)(settings.api_key), {
            method: 'post',
            json: {
                type: 'identify',
                userId: payload.userId,
                traits: traits,
                timestamp: payload.timestamp
            }
        });
    }
};
exports.default = action;
//# sourceMappingURL=index.js.map