/**
 * Copyright © CENRA (2016)
 *
 * remi.clement@espaces-naturels.fr
 *
 * This software is a multi-platform and portable application based on
 * the scientifical toolbox to monitor wetlands. With this toolbox it’s
 * possible to calculate indicators «RhoMéO» to monitor quality,
 * fonctionalities and urban and agricultural pressures of wetlands.
 * Indicators are calculated using naturalist data entered and/or imported,
 * and geographic data downloaded from a geographic server.
 *
 * This software is governed by the CeCILL license under French law and
 * abiding by the rules of distribution of free software.  You can  use,
 * modify and/ or redistribute the software under the terms of the CeCILL
 * license as circulated by CEA, CNRS and INRIA at the following URL
 * "http://www.cecill.info".
 *
 * As a counterpart to the access to the source code and  rights to copy,
 * modify and redistribute granted by the license, users are provided only
 * with a limited warranty  and the software's author,  the holder of the
 * economic rights,  and the successive licensors  have only  limited
 * liability.
 *
 * In this respect, the user's attention is drawn to the risks associated
 * with loading,  using,  modifying and/or developing or reproducing the
 * software by the user in light of its specific status of free software,
 * that may mean  that it is complicated to manipulate,  and  that  also
 * therefore means  that it is reserved for developers  and  experienced
 * professionals having in-depth computer knowledge. Users are therefore
 * encouraged to load and test the software's suitability as regards their
 * requirements in conditions enabling the security of their systems and/or
 * data to be ensured and,  more generally, to use and operate it in the
 * same conditions as regards security.
 *
 * The fact that you are presently reading this means that you have had
 * knowledge of the CeCILL license and that you accept its terms.
*/
package fr.cenra.rhomeo.protocol.p04;

import fr.cenra.rhomeo.api.data.Statement;
import fr.cenra.rhomeo.api.data.Warning;
import java.time.LocalDate;
import java.util.Objects;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import org.hibernate.validator.constraints.NotBlank;
import org.hibernate.validator.constraints.Range;

/**
 *
 * @author Alexis Manin (Geomatys)
 */
@P04Validation
public class P04Statement extends Statement {

    private final SimpleIntegerProperty year = new SimpleIntegerProperty();

    /**
     * Note : Code extracted from a public document : Corine Biotope
     */
    private final SimpleStringProperty habitatProperty = new SimpleStringProperty();

    private final SimpleDoubleProperty humineProperty = new SimpleDoubleProperty();

    private final SimpleDoubleProperty acidsProperty = new SimpleDoubleProperty();

    private final SimpleDoubleProperty ptProperty = new SimpleDoubleProperty();

    private final SimpleDoubleProperty cotProperty = new SimpleDoubleProperty();

    // Set a default constructor setting a valid date, to succeed on constraint validation.
    public P04Statement() {
        date.set(LocalDate.now());
    }

    @Range(min = 2000, max = 2100, payload = Warning.class, message = "L'année saisie n'appartient pas au 21ᵉ siècle")
    public int getYear() {
        return year.get();
    }

    @NotBlank(message = "Un habitat doit être saisi")
    public String getHabitat() {
        return habitatProperty.get();
    }

    public double getHumine() {
        return humineProperty.get();
    }

    public double getAcids() {
        return acidsProperty.get();
    }

    public double getPt() {
        return ptProperty.get();
    }

    public double getCot() {
        return cotProperty.get();
    }

    public void setYear(final int year) {
        this.year.set(year);
    }

    public void setHabitat(final String habitat) {
        habitatProperty.set(habitat);
    }

    public void setHumine(final double humine) {
        humineProperty.set(humine);
    }

    public void setAcids(final double acids) {
        acidsProperty.set(acids);
    }

    public void setPt(final double pt) {
        ptProperty.set(pt);
    }

    public void setCot(final double cot) {
        cotProperty.set(cot);
    }

    public IntegerProperty yearProperty() {
        return year;
    }

    public StringProperty habitatProperty() {
        return habitatProperty;
    }

    public DoubleProperty humineProperty() {
        return humineProperty;
    }

    public DoubleProperty acidsProperty() {
        return acidsProperty;
    }

    public SimpleDoubleProperty ptProperty() {
        return ptProperty;
    }

    public SimpleDoubleProperty cotProperty() {
        return cotProperty;
    }

    /**
     * We must have only one statement per year and "habitat", so they're the
     * only terms of the equation.
     *
     * @param obj
     * @return
     */
    @Override
    public boolean equals(Object obj) {
        if (obj instanceof P04Statement) {
            final P04Statement other = (P04Statement) obj;
            return year.get() == other.year.get() && Objects.equals(habitatProperty.get(), other.habitatProperty.get());
        }

        return false;
    }

    @Override
    public int hashCode() {
        return habitatProperty.get() == null ? year.get() : year.get() + 7 * habitatProperty.get().hashCode();
    }
}
