"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LinkedInAudiences = void 0;
const constants_1 = require("./constants");
class LinkedInAudiences {
    constructor(request) {
        this.request = request;
    }
    async getProfile() {
        return this.request(`${constants_1.BASE_URL}/me`, {
            method: 'GET'
        });
    }
    async getAdAccountUserProfile(settings, userId) {
        return this.request(`${constants_1.BASE_URL}/adAccountUsers/account=urn:li:sponsoredAccount:${settings.ad_account_id}&user=urn:li:person:${userId}`, {
            method: 'GET'
        });
    }
    async getDmpSegment(settings, payload) {
        return this.request(`${constants_1.BASE_URL}/dmpSegments`, {
            method: 'GET',
            searchParams: {
                q: 'account',
                account: `urn:li:sponsoredAccount:${settings.ad_account_id}`,
                sourceSegmentId: payload.personas_audience_key || '',
                sourcePlatform: constants_1.LINKEDIN_SOURCE_PLATFORM
            }
        });
    }
    async createDmpSegment(settings, payload) {
        return this.request(`${constants_1.BASE_URL}/dmpSegments`, {
            method: 'POST',
            json: {
                name: payload.dmp_segment_name,
                sourcePlatform: constants_1.LINKEDIN_SOURCE_PLATFORM,
                sourceSegmentId: payload.personas_audience_key,
                account: `urn:li:sponsoredAccount:${settings.ad_account_id}`,
                type: 'USER',
                destinations: [
                    {
                        destination: 'LINKEDIN'
                    }
                ]
            }
        });
    }
    async batchUpdate(dmpSegmentId, elements) {
        return this.request(`${constants_1.BASE_URL}/dmpSegments/${dmpSegmentId}/users`, {
            method: 'POST',
            headers: {
                'X-RestLi-Method': 'BATCH_CREATE'
            },
            json: {
                elements
            },
            throwHttpErrors: false
        });
    }
}
exports.LinkedInAudiences = LinkedInAudiences;
//# sourceMappingURL=api.js.map