package com.adobe.primetime.reference.manager;

import android.content.Context;

import com.adobe.mediacore.BillingMetricsConfiguration;
import com.adobe.mediacore.MediaPlayerItemConfig;
import com.adobe.primetime.reference.config.IBillingConfig;

public class BillingManager implements IManager {

    private Context context;
    private IBillingConfig config;

    public static final String SETTINGS_BILLING_USE_CUSTOM = "settings_billing_use_custom";
    public static final String SETTINGS_BILLING_ENABLED = "settings_billing_enabled";
    public static final String SETTINGS_BILLING_PUBLISHER = "settings_billing_publisher";
    public static final String SETTINGS_BILLING_REPORT_SUITE = "settings_billing_report_suite";
    public static final String SETTINGS_BILLING_VISITOR = "settings_billing_visitor";
    public static final String SETTINGS_BILLING_TRACKING_SERVER = "settings_billing_tracking_server";
    public static final String SETTINGS_BILLING_STD_DURATION = "settings_billing_std_duration";
    public static final String SETTINGS_BILLING_PRO_DURATION = "settings_billing_pro_duration";
    public static final String SETTINGS_BILLING_LIVE_DURATION = "settings_billing_live_duration";

    // Default configuration values for the Adobe Billing Analytics.
    // Please consult with your Adobe Primetime enablement team member for the correct values for your account.
    public static final boolean DEFAULT_BILLING_USE_CUSTOM = false;
    public static final boolean DEFAULT_BILLING_ENABLED = true;
    public static final String DEFAULT_BILLING_PUBLISHER = "";
    public static final String DEFAULT_BILLING_REPORT_SUITE = "";
    public static final String DEFAULT_BILLING_VISITOR = "";
    public static final String DEFAULT_BILLING_TRACKING_SERVER = "";
    public static final double DEFAULT_BILLING_STD_DURATION = 30;
    public static final double DEFAULT_BILLING_PRO_DURATION = 30;
    public static final double DEFAULT_BILLING_LIVE_DURATION = 30;

    protected BillingManager(IBillingConfig config, Context context)
    {
        this.context = context;
        this.config = config;
    }

    public void setBillingConfiguration(MediaPlayerItemConfig itemConfig)
    {
        // Do not use production report suite for testing
        // To use production report suite, use native configuration by not setting ReportSuiteId
        BillingMetricsConfiguration configuration = new BillingMetricsConfiguration();
        configuration.setReportSuiteId("ptebillingtest");

        // set user provided values
        if (config.useCustom()) {
            configuration.setEnabled(config.isEnabled());

            if (!"".equals(config.getReportSuite()))
                configuration.setReportSuiteId(config.getReportSuite());

            if (!"".equals(config.getVisitor()))
                configuration.setVisitorId(config.getVisitor());

            if (!"".equals(config.getPublisher()))
                configuration.setPublisherId(config.getPublisher());

            if (!"".equals(config.getTrackingServer()))
                configuration.setTrackingServer(config.getTrackingServer());

            configuration.setStdVODBillableDurationMinutes(config.getStdBillableDurationMinutes());

            configuration.setProVODBillableDurationMinutes(config.getProBillableDurationMinutes());

            configuration.setLiveBillableDurationMinutes(config.getLiveBillableDurationMinutes());
        }

        itemConfig.setBillingMetricsConfiguration(configuration);

    }

    @Override
    public void destroy() {

    }
}
