package com.ecep.contract.util;

import java.util.HashMap;
import java.util.Locale;

import com.ecep.contract.SpringApp;
import com.ecep.contract.ds.company.service.CompanyFileService;
import com.ecep.contract.ds.company.service.CompanyFileTypeService;
import com.ecep.contract.ds.company.service.CompanyService;
import com.ecep.contract.ds.contract.service.ContractBidVendorService;
import com.ecep.contract.ds.contract.service.ContractFileService;
import com.ecep.contract.ds.contract.service.ContractFileTypeService;
import com.ecep.contract.ds.contract.service.ContractService;
import com.ecep.contract.ds.customer.service.CompanyCustomerFileService;
import com.ecep.contract.ds.customer.service.CompanyCustomerFileTypeService;
import com.ecep.contract.ds.customer.service.CompanyCustomerService;
import com.ecep.contract.ds.other.service.EmployeeService;
import com.ecep.contract.ds.project.service.ProjectFileService;
import com.ecep.contract.ds.project.service.ProjectFileTypeService;
import com.ecep.contract.ds.project.service.ProjectService;
import com.ecep.contract.ds.vendor.service.VendorFileService;
import com.ecep.contract.ds.vendor.service.VendorFileTypeService;
import com.ecep.contract.ds.vendor.service.VendorGroupService;
import com.ecep.contract.ds.vendor.service.VendorService;

import lombok.Getter;
import lombok.Setter;

public class VerifyContext {
    @Getter
    @Setter
    private Locale locale = Locale.getDefault();
    private HashMap<Class<?>, Object> cachedMap = new HashMap<>();

    public <K> K getBean(Class<K> requiredType) {
        @SuppressWarnings("unchecked")
        K bean = (K) cachedMap.get(requiredType);
        if (bean == null) {
            bean = SpringApp.getBean(requiredType);
            cachedMap.put(requiredType, bean);
        }
        return bean;
    }

    // Employee
    protected EmployeeService getEmployeeService() {
        return getBean(EmployeeService.class);
    }

    // Project
    protected ProjectService getProjectService() {
        return getBean(ProjectService.class);
    }

    protected ProjectFileService getProjectFileService() {
        return getBean(ProjectFileService.class);
    }

    protected ProjectFileTypeService getProjectFileTypeService() {
        return getBean(ProjectFileTypeService.class);
    }

    // Contract
    protected ContractService getContractService() {
        return getBean(ContractService.class);
    }

    protected ContractFileTypeService getContractFileTypeService() {
        return getBean(ContractFileTypeService.class);
    }

    protected ContractFileService getContractFileService() {
        return getBean(ContractFileService.class);
    }

    protected ContractBidVendorService getContractBidVendorService() {
        return getBean(ContractBidVendorService.class);
    }

    // Company
    protected CompanyService getCompanyService() {
        return getBean(CompanyService.class);
    }

    protected CompanyFileTypeService getCompanyFileTypeService() {
        return getBean(CompanyFileTypeService.class);
    }

    protected CompanyFileService getCompanyFileService() {
        return getBean(CompanyFileService.class);
    }

    // Vendor
    protected VendorService getVendorService() {
        return getBean(VendorService.class);
    }

    protected VendorGroupService getVendorGroupService() {
        return getBean(VendorGroupService.class);
    }

    protected VendorFileTypeService getVendorFileTypeService() {
        return getBean(VendorFileTypeService.class);
    }

    protected VendorFileService getVendorFileService() {
        return getBean(VendorFileService.class);
    }

    // Customer

    protected CompanyCustomerService getCompanyCustomerService() {
        return getBean(CompanyCustomerService.class);
    }

    protected CompanyCustomerFileTypeService getCompanyCustomerFileTypeService() {
        return getBean(CompanyCustomerFileTypeService.class);
    }

    protected CompanyCustomerFileService getCompanyCustomerFileService() {
        return getBean(CompanyCustomerFileService.class);
    }
}
