package com.example.samplejavaapp.wrappers

import android.content.Context
import com.example.samplejavaapp.wrappers.event.JEventHandler
import com.example.samplejavaapp.wrappers.message.JMessageHandler
import com.example.samplejavaapp.wrappers.sdk.JClient
import pl.novelpay.client.core.configuration.PackageInfo
import pl.novelpay.client.core.configuration.SDKConfiguration
import pl.novelpay.client.sdk.ClientFactory
import pl.novelpay.retailer.configuration.RetailerConfiguration

class JClientFactory constructor(
    private val factory: ClientFactory
) {
    fun bindConfiguration(
        appName: String,
        appPackage: String
    ): JClientFactory {
        factory.bindConfiguration(
            SDKConfiguration.defaultConfiguration(
                clientApplicationInfo = PackageInfo(
                    applicationName = appName,
                    applicationPackage = appPackage
                )
            )
        )
        return this
    }

    fun bindContext(context: Context): JClientFactory {
        factory.bindContext(context)
        return this
    }

    fun bindEventObserver(observer: JEventHandler): JClientFactory {
        factory.bindEventObserver(observer)
        return this
    }

    fun bindInterceptor(handler: JMessageHandler): JClientFactory {
        factory.bindInterceptor(handler)
        return this
    }

    fun bindProtocolConfiguration(saleId: String): JClientFactory {
        factory.bindProtocolConfiguration(
            RetailerConfiguration(
                saleID = saleId
            )
        )
        return this
    }

    fun build() = JClient(factory.build())
}