/********************************************************************
 * Copyright © 2004 EDS. All rights reserved
 ********************************************************************/
package gov.va.med.esr.common.builder.entity;

import gov.va.med.esr.common.model.ee.ConflictExperience;
import gov.va.med.esr.common.model.lookup.ConflictLocation;
import gov.va.med.fw.util.builder.Builder;
import gov.va.med.fw.util.builder.BuilderException;

/**
 * Builds a rated disability from a message and a person if elements in the ZRD
 * segments are present
 * 
 * @author Carlos Ruiz
 * @version 1.0
 */
public class ConflictExperienceBuilder
    extends EntityBuilder
{
    /**
	 * An instance of serialVersionUID
	 */
	private static final long serialVersionUID = -353302701923165442L;
	private Builder conflictBuilder;

    /**
     * Default constructor.
     */
    public ConflictExperienceBuilder()
    {
        super();
    }

    public Builder getConflictBuilder()
    {
        return this.conflictBuilder;
    }

    public void setConflictBuilder(Builder conflictBuilder)
    {
        this.conflictBuilder = conflictBuilder;
    }

    public ConflictExperience build(ConflictExperienceMetaData metaData)
        throws BuilderException
    {
        ConflictExperience input = metaData.getEntity();
        ConflictExperience output = (input == null) ? new ConflictExperience()
            : input;

        this.transfer(output, metaData);

        return this.shouldKeep(output) ? output : null;
    }
   
     private ConflictLocation buildConflict(ConflictLocation input, String code)
        throws BuilderException
    {
        return super.shouldDelete(code) ? null : (ConflictLocation)super
            .build(this.conflictBuilder, input, code);
    }

    private boolean shouldKeep(ConflictExperience obj)
    {
        return ((obj.getConflictLocation() != null));
    }

    private void transfer(
        ConflictExperience input,
        ConflictExperienceMetaData metaData) throws BuilderException
    {
        input.setConflictLocation(this.buildConflict(input.getConflictLocation(), metaData
            .getConflict()));
        input
            .setEndDate(super.build(input.getEndDate(), metaData.getEndDate()));
        input.setStartDate(super.build(input.getStartDate(), metaData
            .getStartDate()));
    } 
}