package com.banesco.common.infrastructure.config;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import lombok.Getter;
import org.eclipse.microprofile.config.Config;

import java.util.Arrays;
import java.util.List;

@ApplicationScoped
@Getter
public class DataSourceConfig {

    private final String spName;

    private final String spIbsError;

    private final List<String> spAccountStatusEnable;
    private final List<String> spAccountStatusDisabled;

    private final List<String> spAccountTypeSaving;
    private final List<String> spAccountTypeCurrent;
    private final List<String> spAccountTypeInterestArrangement;

    private final List<String> spAccountParent;

    private final List<String> spCurrencyBase;

    @Inject
    public DataSourceConfig(Config config) {
        this.spName = config.getValue("datasource.sp.name", String.class);

        this.spIbsError = config.getValue("datasource.sp.errors.ibs", String.class).toUpperCase();

        this.spAccountStatusEnable = Arrays.stream(config.getValue(
            "datasource.sp.allowed.account-status.enable",
            String.class
        ).toUpperCase().split(",")).toList();
        this.spAccountStatusDisabled = Arrays.stream(config.getValue(
            "datasource.sp.allowed.account-status.disable",
            String.class
        ).toUpperCase().split(",")).toList();

        this.spAccountTypeSaving = Arrays.stream(config.getValue(
            "datasource.sp.allowed.account-type.saving",
            String.class
        ).toUpperCase().split(",")).toList();
        this.spAccountTypeCurrent = Arrays.stream(config.getValue(
            "datasource.sp.allowed.account-type.current",
            String.class
        ).toUpperCase().split(",")).toList();
        this.spAccountTypeInterestArrangement = Arrays.stream(config.getValue(
            "datasource.sp.allowed.account-type.interest-arrangement",
            String.class
        ).toUpperCase().split(",")).toList();

        this.spAccountParent = Arrays.stream(config.getValue(
            "datasource.sp.allowed.account-relationship-type.parent",
            String.class
        ).toUpperCase().split(",")).toList();

        this.spCurrencyBase = Arrays.stream(config.getValue(
            "datasource.sp.allowed.currency.base",
            String.class
        ).toUpperCase().split(",")).toList();
    }
}