package com.example.samplejavaapp;

import android.os.Bundle;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.example.samplejavaapp.processing.EventObserver;
import com.example.samplejavaapp.processing.MessageInterceptor;
import com.example.samplejavaapp.wrappers.JClientFactory;
import com.example.samplejavaapp.wrappers.sdk.JClient;

import pl.novelpay.client.sdk.ClientFactory;

public class MainActivity extends AppCompatActivity {

    private JClient sdk;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        sdkInit();
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
        sdk.sendLoginRequest();
        sdk.sendLogoutRequest();
    }

    private void sdkInit() {
        sdk = new JClientFactory(ClientFactory.INSTANCE)
                .bindConfiguration("sample", "com.example.samplejavaapp")
                .bindProtocolConfiguration("SampleSaleID")
                .bindContext(getApplicationContext())
                .bindEventObserver(new EventObserver())
                .bindInterceptor(new MessageInterceptor())
                .build();
    }
}
