/*
 * Copyright (C) 2022 - Florindo Smilari (spherIC)
 */
package ch.spherIC.recurvebowsight.model.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.StringTokenizer;

import ch.spherIC.recurvebowsight.model.ISight;


/**
 * @author F. Smilari
 */
public class Sight implements ISight {

    private long id;
    private String manufacturer;
    private String model;
    private Double aV;
    private Double aH;
    private String heVis;
    private Double vertSkalaRangMin;
    private Double vertSkalaRangMax;
    private Double pointerOffset;

    /**
     * Konstruktor.
     *
     * @param id
     * @param manufacturer
     * @param model
     * @param aV
     * @param aH
     * @param heVis
     * @param vertSkalaRangMin
     * @param vertSkalaRangMax
     */
    public Sight(final long id, final String manufacturer, final String model, final Double aV,
                 final Double aH, final String heVis, final Double vertSkalaRangMin,
                 final Double vertSkalaRangMax, final Double pointerOffset) {
        super();
        this.id = id;
        this.manufacturer = manufacturer;
        this.model = model;
        this.aV = aV;
        this.aH = aH;
        this.heVis = heVis;
        this.vertSkalaRangMin = vertSkalaRangMin;
        this.vertSkalaRangMax = vertSkalaRangMax;
        this.pointerOffset = pointerOffset;
    }

    /**
     * @return the id
     */
    @Override
    public long getId() {
        return this.id;
    }

    /**
     * @param id the id to set
     */
    @Override
    public void setId(final long id) {
        this.id = id;
    }

    /**
     * @return the manufacturer
     */
    @Override
    public String getManufacturer() {
        return this.manufacturer;
    }

    /**
     * @param manufacturer the manufacturer to set
     */
    @Override
    public void setManufacturer(final String manufacturer) {
        this.manufacturer = manufacturer;
    }

    /**
     * @return the model
     */
    @Override
    public String getModel() {
        return this.model;
    }

    /**
     * @param model the model to set
     */
    @Override
    public void setModel(final String model) {
        this.model = model;
    }


    @Override
    public Double getAV() {
        return this.aV;
    }

    @Override
    public void setAV(final Double aV) {
        this.aV = aV;
    }

    @Override
    public Double getAH() {
        return this.aH;
    }

    @Override
    public void setAH(final Double aH) {
        this.aH = aH;
    }

    @Override
    public String getHeVis() {
        return this.heVis;
    }

    @Override
    public void setHeVis(final String heVis) {
        this.heVis = heVis;
    }

    @Override
    public Double getVertSkalaRangeMin() {
        return this.vertSkalaRangMin;
    }

    @Override
    public void setVertSkalaRangeMin(final Double vertSkalaRangMin) {
        this.vertSkalaRangMin = vertSkalaRangMin;
    }

    @Override
    public Double getVertSkalaRangeMax() {
        return this.vertSkalaRangMax;
    }

    @Override
    public void setVertSkalaRangeMax(final Double vertSkalaRangMax) {
        this.vertSkalaRangMax = vertSkalaRangMax;
    }

    @Override
    public Double getPointerOffset() {
        return this.pointerOffset;
    }

    @Override
    public void setPointerOffset(final Double pointerOffset) {
        this.pointerOffset = pointerOffset;
    }


    @Override
    public List<Double> getHeVisList() {

        List<Double> list = new ArrayList<Double>();

        if (this.heVis != null && !this.heVis.isEmpty()) {
            StringTokenizer st = new StringTokenizer(this.heVis, ",");
            while (st.hasMoreTokens()) {
                try {
                    list.add(Double.valueOf(st.nextToken()));
                } catch (NumberFormatException e) {
                    continue;
                }
            }
        }

        return list;
    }


    @Override
    public String toString() {
        if (this.id == -999) {
            return getManufacturer();
        }
        return getManufacturer() + " " + getModel();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Sight sight = (Sight) o;
        return id == sight.id && manufacturer.equals(sight.manufacturer) && model.equals(sight.model);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, manufacturer, model);
    }
}
