package de.hft.stuttgart.citydoctor2.checks.semantics;

import java.util.Collections;
import java.util.Set;

import de.hft.stuttgart.citydoctor2.check.Check;
import de.hft.stuttgart.citydoctor2.check.CheckId;
import de.hft.stuttgart.citydoctor2.check.CheckResult;
import de.hft.stuttgart.citydoctor2.check.Requirement;
import de.hft.stuttgart.citydoctor2.check.RequirementType;
import de.hft.stuttgart.citydoctor2.check.ResultStatus;
import de.hft.stuttgart.citydoctor2.check.error.PolygonWithoutSurfaceError;
import de.hft.stuttgart.citydoctor2.datastructure.Lod;
import de.hft.stuttgart.citydoctor2.datastructure.Polygon;

public class PolygonWithoutSurfaceCheck extends Check {

	@Override
	public void check(Polygon poly) {
		Lod lod = poly.getParent().getLod();
		if (lod == Lod.LOD2 || lod == Lod.LOD3 || lod == Lod.LOD4) {
			// only check LOD2-4
			CheckResult cr;
			if (poly.getPartOfSurface() == null) {
				PolygonWithoutSurfaceError err = new PolygonWithoutSurfaceError(poly);
				cr = new CheckResult(this, ResultStatus.ERROR, err);
			} else {
				cr = new CheckResult(this, ResultStatus.OK, null);
			}
			poly.addCheckResult(cr);
		}
	}

	@Override
	public Set<Requirement> appliesToRequirements() {
		return Collections.singleton(Requirement.R_SE_POLYGON_WITHOUT_SURFACE);
	}

	@Override
	public CheckId getCheckId() {
		return CheckId.C_SE_POLYGON_WITHOUT_SURFACE;
	}

	@Override
	public RequirementType getType() {
		return RequirementType.SEMANTIC;
	}

	@Override
	public Check createNewInstance() {
		return new PolygonWithoutSurfaceCheck();
	}

}
