import { NativeModules } from 'react-native'

import { createInteractor } from '../architecture/Interactor'
import { AirbridgeTrackingBlocklist } from '../constant/AirbridgeTrackingBlocklist'

export const createDependency = () => {}

type SwitchInteractor = {
    enableSDK(): void
    disableSDK(): void
    isSDKEnabled(): Promise<boolean>

    startTracking(): void
    stopTracking(): void
    isTrackingEnabled(): Promise<boolean>

    startInAppPurchaseTracking(): void
    stopInAppPurchaseTracking(): void
    isInAppPurchaseTrackingEnabled(): Promise<boolean>

    allowTrackingItem(item: string): void
    blockTrackingItem(item: string): void
}

createDependency.SwitchModule = () => ({
    interactor: createInteractor<SwitchInteractor>(NativeModules.SwitchInteractor),
})

export type SwitchModule = ReturnType<typeof createSwitchModule>

export const createSwitchModule= () => {
    // create dependency
    const { interactor } = createDependency.SwitchModule()

    // define method
    const enableSDK = () => {
        interactor.enableSDK()
    }

    const disableSDK = () => {
        interactor.disableSDK()
    }

    const isSDKEnabled = () => {
        return interactor.isSDKEnabled()
    }

    const startTracking = () => {
        interactor.startTracking()
    }

    const stopTracking = () => {
        interactor.stopTracking()
    }

    const isTrackingEnabled = () => {
        return interactor.isTrackingEnabled()
    }

    const startInAppPurchaseTracking = () => {
        interactor.startInAppPurchaseTracking()
    }

    const stopInAppPurchaseTracking = () => {
        interactor.stopInAppPurchaseTracking()
    }

    const isInAppPurchaseTrackingEnabled = () => {
        return interactor.isInAppPurchaseTrackingEnabled()
    }

    const allowTrackingItem = (item: AirbridgeTrackingBlocklist) => {
        interactor.allowTrackingItem(item.toString())
    }

    const blockTrackingItem = (item: AirbridgeTrackingBlocklist) => {
        interactor.blockTrackingItem(item.toString())
    }

    // create object
    return {
        enableSDK,
        disableSDK,
        isSDKEnabled,
        startTracking,
        stopTracking,
        isTrackingEnabled,
        startInAppPurchaseTracking,
        stopInAppPurchaseTracking,
        isInAppPurchaseTrackingEnabled,
        allowTrackingItem,
        blockTrackingItem
    }
}
