/**
 * Copyright © 2022 Anagog Ltd. All rights reserved.
 */

import { NativeModules } from 'react-native';
import { Campaign } from './models/Campaign';
import { AnagogSDK } from './AnagogSDK';
const { JedAIModule } = NativeModules;

export class AnagogTools {

    /**
     * Sync campaigns.
     * Download all your campaigns to your app.
     * @returns `Promise` with no parameters.
     */
    static syncCampaigns(): Promise<void> {
        return JedAIModule.syncCampaigns();
    }

    /**
     * Simulate a campaign, use this API to test your campaigns as defined.
     * @param campaignIdentifier A campaign identifier to simulate. Pass null to simulates all your campaigns.
     * @returns `Promise` with no parameters.
     */
    static simulateCampaign(campaignIdentifier: string | null): Promise<void> {
        return JedAIModule.simulateCampaign(campaignIdentifier)
    }

    /**
     * Get available campaigns.
     * @returns `Promise<Campaign[]>` with list of `Campaign` objects.
     */
    static getCampaigns(): Promise<Campaign[]> {
        return JedAIModule.getCampaigns()
            .then((json: any[]) => {
                return json.map(campaign => new Campaign(campaign['title'], campaign['identifier']));
            })
    }

    /**
     * Generate and send SDK reports.
     * @returns `Promise` with no parameters.
     */
    static forceScheduleReports(): Promise<void> {
        return JedAIModule.forceScheduleReports();
    }

    /**
     * Show JedAI SDK debugging screen.
     * Use this API to open the JedAI SDK builtin debugging screen for easy integration.
     * @returns `Promise` with no parameters.
     */
    static openDebuggingScreen(): Promise<Object> {
        return JedAIModule.openDebuggingScreen({
            version: AnagogSDK.packageVersion,
        });
    }

}