/********************************************************************
 * Copyright © 2005 VHA. All rights reserved
 ********************************************************************/
package gov.va.med.esr.common.model;

// Java classes
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import gov.va.med.esr.common.model.comms.CommsLogEntry;
import gov.va.med.esr.common.model.comms.HandBookMailQueue;
import gov.va.med.esr.common.model.ee.ConflictExperience;
import gov.va.med.esr.common.model.ee.EGTSetting;
import gov.va.med.esr.common.model.ee.MilitaryServiceEpisode;
import gov.va.med.esr.common.model.ee.PrisonerOfWar;
import gov.va.med.esr.common.model.ee.PurpleHeart;
import gov.va.med.esr.common.model.ee.SHAD;
import gov.va.med.esr.common.model.financials.DependentFinancials;
import gov.va.med.esr.common.model.financials.SpouseFinancials;
import gov.va.med.esr.common.model.hbp.HealthBenefitPlanName;
import gov.va.med.esr.common.model.lookup.HandBookMailStatusType;
import gov.va.med.esr.common.model.lookup.RegistryType;
import gov.va.med.esr.common.model.party.Address;
import gov.va.med.esr.common.model.party.Email;
import gov.va.med.esr.common.model.party.Phone;
import gov.va.med.esr.common.model.person.Association;
import gov.va.med.esr.common.model.person.Dependent;
import gov.va.med.esr.common.model.person.PersonMergeInfo;
import gov.va.med.esr.common.model.person.PersonUnmergeInfo;
import gov.va.med.esr.common.model.person.PreferredFacility;
import gov.va.med.esr.common.model.person.SSN;
import gov.va.med.esr.common.model.person.Spouse;
import gov.va.med.esr.common.model.person.id.PersonIdEntityKey;
import gov.va.med.esr.common.model.person.id.PersonIdEntityKeyImpl;
import gov.va.med.esr.common.model.person.id.VPIDEntityKey;
import gov.va.med.esr.common.model.person.id.VPIDEntityKeyImpl;
import gov.va.med.esr.common.model.report.CompletedReport;
import gov.va.med.esr.common.model.report.ReportSetup;
import gov.va.med.esr.common.model.report.SimpleCompletedReport;
import gov.va.med.esr.common.model.security.ESRUserPrincipalImpl;
import gov.va.med.fw.model.EntityKey;
import gov.va.med.fw.model.EntityKeyFactory;

/**
 * This class provides entity keys for various BOM objects.
 *
 * @author Andrew Pach
 * @version 3.0
 */
public class CommonEntityKeyFactory
{
    /**
     * This class doesn't need to be instantiated.
     */
    private CommonEntityKeyFactory()
    {
    }

    public static PersonIdEntityKey createPersonIdEntityKey(String id)
    {
        return new PersonIdEntityKeyImpl(new BigDecimal(id));
    }

    public static PersonIdEntityKey createPersonIdEntityKey(Serializable id)
    {
        return new PersonIdEntityKeyImpl(id);
    }

    public static VPIDEntityKey createVPIDEntityKey(String VPID)
    {
        return new VPIDEntityKeyImpl(VPID);
    }

    public static VPIDEntityKey createVPIDEntityKey(gov.va.med.esr.service.external.person.VPIDEntityKey VPID)
    {
        return new VPIDEntityKeyImpl(VPID.getVPID());
    }

    public static EntityKey createCommsLogEntryEntityKey(String id)
    {
        return EntityKeyFactory.createEntityKey(new BigDecimal(id), CommsLogEntry.class);
    }

    public static EntityKey createHandBookMailStatusTypeEntityKey(String id)
    {
        return EntityKeyFactory.createEntityKey(new BigDecimal(id), HandBookMailStatusType.class);
    }

    public static EntityKey createHandBookMailQueueEntityKey(String id)
    {
        return EntityKeyFactory.createEntityKey(new BigDecimal(id), HandBookMailQueue.class);
    }

    public static EntityKey createAssociationEntityKey(String id)
    {
        return EntityKeyFactory.createEntityKey(new BigDecimal(id), Association.class);
    }

    public static EntityKey createSpouseEntityKey(String id)
    {
        return EntityKeyFactory.createEntityKey(new BigDecimal(id), Spouse.class);
    }
    
    public static EntityKey createSpouseFinancialsEntityKey(String id)
    {
        return EntityKeyFactory.createEntityKey(new BigDecimal(id), SpouseFinancials.class);
    }
    
    public static EntityKey createDependentFinancialsEntityKey(String id)
    {
        return EntityKeyFactory.createEntityKey(new BigDecimal(id), DependentFinancials.class);
    }

    public static EntityKey createSSNEntityKey(String id)
    {
        return EntityKeyFactory.createEntityKey(new BigDecimal(id), SSN.class);
    }

    public static EntityKey createDependentEntityKey(String id)
    {
        return EntityKeyFactory.createEntityKey(new BigDecimal(id), Dependent.class);
    }

    public static EntityKey createAddressEntityKey(String id)
    {
        return EntityKeyFactory.createEntityKey(new BigDecimal(id), Address.class);
    }

    public static EntityKey createPersonMergeInfoEntityKey(String id)
    {
        return EntityKeyFactory.createEntityKey(new BigDecimal(id), PersonMergeInfo.class);
    }

    public static EntityKey createPersonUnmergeInfoEntityKey(String id)
    {
        return EntityKeyFactory.createEntityKey(new BigDecimal(id), PersonUnmergeInfo.class);
    }

    public static Set convertExternalEntityKeys(Set externalKeys, Class clazz)
    {
        if(externalKeys == null || externalKeys.size() == 0)
            return null;

        Set convertedKeys = new HashSet();
        Iterator itr = externalKeys != null ? externalKeys.iterator() : null;
        while(itr != null && itr.hasNext())
            convertedKeys.add(convertExternalEntityKey((gov.va.med.esr.service.external.person.EntityKey) itr.next(), clazz));
        return convertedKeys;
    }

    public static EntityKey convertExternalEntityKey(gov.va.med.esr.service.external.person.EntityKey id, Class clazz)
    {
        return EntityKeyFactory.createEntityKey(new BigDecimal(id.getKey()), clazz);
    }

    public static EntityKey createPhoneEntityKey(String id)
    {
        return EntityKeyFactory.createEntityKey(new BigDecimal(id), Phone.class);
    }


    public static EntityKey createEmailEntityKey(String id)
    {
        return EntityKeyFactory.createEntityKey(new BigDecimal(id), Email.class);
    }


    public static EntityKey createMilitaryServiceEpisodeEntityKey(String id)
    {
        return EntityKeyFactory.createEntityKey(new BigDecimal(id), MilitaryServiceEpisode.class);
    }

    public static EntityKey createConflictExperienceEntityKey(String id)
    {
        return EntityKeyFactory.createEntityKey(new BigDecimal(id), ConflictExperience.class);
    }

    public static EntityKey createEGTSettingEntityKey(String id)
    {
        return EntityKeyFactory.createEntityKey(new BigDecimal(id), EGTSetting.class);
    }

    public static EntityKey createRegistryEntityKey(String id, RegistryType type)
    {
        if(type == null)
            return null;

        if(RegistryType.CODE_PH_REGISTRY.getCode().equals(type.getCode()))
            return createPurpleHeartEntityKey(id);
        else if(RegistryType.CODE_POW_REGISTRY.getCode().equals(type.getCode()))
            return createPrisonerOfWarEntityKey(id);
        else if(RegistryType.CODE_SHAD_REGISTRY.getCode().equals(type.getCode()))
            return createSHADEntityKey(id);

        return null;
    }

    public static EntityKey createPurpleHeartEntityKey(String id)
    {
        return EntityKeyFactory.createEntityKey(new BigDecimal(id), PurpleHeart.class);
    }

    public static EntityKey createPrisonerOfWarEntityKey(String id)
    {
        return EntityKeyFactory.createEntityKey(new BigDecimal(id), PrisonerOfWar.class);
    }

    public static EntityKey createSHADEntityKey(String id)
    {
        return EntityKeyFactory.createEntityKey(new BigDecimal(id), SHAD.class);
    }

    public static EntityKey createCompletedReportEntityKey(String id)
    {
        return EntityKeyFactory.createEntityKey(new BigDecimal(id), CompletedReport.class);
    }
    
    public static EntityKey createSimpleCompletedReportEntityKey(String id)
    {
        return EntityKeyFactory.createEntityKey(new BigDecimal(id), SimpleCompletedReport.class);
    }
    
    public static EntityKey createReportSetupEntityKey(String id)
    {
        return EntityKeyFactory.createEntityKey(new BigDecimal(id), ReportSetup.class);
    }
    
    public static EntityKey createUserPrincipalEntityKey(String id)
    {
        return EntityKeyFactory.createEntityKey(new BigDecimal(id), ESRUserPrincipalImpl.class);
    }    

    public static EntityKey createPreferredFacilityEntityKey(String id)
    {
        return EntityKeyFactory.createEntityKey(new BigDecimal(id), PreferredFacility.class);
    }

    public static EntityKey createHealthBenefitPlanNameEntityKey(String id)
    {
        return EntityKeyFactory.createEntityKey(new BigDecimal(id), HealthBenefitPlanName.class);
    }


}
