package com.iqser.red.service.persistence.management.v1.processor.service;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.springframework.stereotype.Service;

import com.knecon.fforesight.tenantcommons.TenantApplicationType;
import com.knecon.fforesight.tenantcommons.TenantContext;
import com.knecon.fforesight.tenantcommons.TenantProvider;

import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldDefaults;

@Service
@RequiredArgsConstructor
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
public class CurrentApplicationTypeProvider {

    TenantProvider tenantProvider;

    Map<String, TenantApplicationType> cache = new ConcurrentHashMap<>();


    public TenantApplicationType get() {

        return cache.computeIfAbsent(TenantContext.getTenantId(), tenantProvider::getTenantApplicationType);
    }


    public boolean isDocuMine() {

        return get().equals(TenantApplicationType.DocuMine);
    }


    public boolean isRedactManager() {

        return get().equals(TenantApplicationType.RedactManager);
    }

}

