package com.ejie.ab39a.validations;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Component;
import com.ejie.ab39a.exceptions.ErrorField;
import com.ejie.ab39a.model.PlanesGestion;

/**
 * Clase encargada de las validaciones de los planes de gestión
 * 
 *  
 *
 */
@Component
public class PlanesGestionValidator {

	/**
	 * Método PlanesEstrategicosValidator
	 */
	public PlanesGestionValidator() {
		super();
	}

	/**
	 * Valida Entidad y devuelve la mapa con los errores.
	 * 
	 * @param planGestion
	 *            PlanesEstrategicos objeto PlanesEstrategicos
	 * @return List<ErrorField> lista de errores
	 */
	public List<ErrorField> validate(PlanesGestion planGestion) {
		List<ErrorField> errorFields = new ArrayList<ErrorField>();

		if (planGestion.getPlanesEstrategicos() == null || planGestion.getPlanesEstrategicos().getCodplane() == null) {
			errorFields.add(new ErrorField("planEstrategico", "validacion.obligatorio"));
		}
		if (planGestion.getAnyo() == null) {
			errorFields.add(new ErrorField("planGestion.anyo", "validacion.obligatorio"));
		}

		if (planGestion.getPlanesEstrategicos().getAnyoinicio() == null
				|| planGestion.getPlanesEstrategicos().getAnyofin() == null) {
			errorFields.add(new ErrorField("planGestion.anyo", "validation.anyo.no.cargado"));
		}

		if (planGestion.getPlanesEstrategicos() != null && planGestion.getAnyo() != null
				&& planGestion.getPlanesEstrategicos().getAnyoinicio() != null
				&& planGestion.getPlanesEstrategicos().getAnyofin() != null
				&& (planGestion.getPlanesEstrategicos().getAnyoinicio() > planGestion.getAnyo()
						|| planGestion.getPlanesEstrategicos().getAnyofin() < planGestion.getAnyo())) {
			errorFields.add(new ErrorField("planGestion.anyo", "validacion.anyo.plan.gestion"));
		}

		return errorFields;
	}

}
