/*
 * Copyright (C) 2025  Tim Zimmermann <tim@aglais.org>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.aglais.zms.db.core.model;

import java.io.Serial;
import java.io.Serializable;
import java.sql.Blob;

/**
 * Class representing a species
 */
public class Species implements Serializable {

    @Serial
    private static final long serialVersionUID = 1;

    private int id;
    private String commonName;
    private String scientificName;
    private String origin;
    private String notes;
    private Blob image;

    /**
     * Create a new {@link Species} object
     *
     * @param id             Species ID as stored in the Database
     * @param commonName     Species common name
     * @param scientificName Species scientific name
     * @param origin         Species origin e.g country
     * @param notes          Additional notes
     * @param image          Image of the species, or null if not available
     */
    public Species(int id, String commonName, String scientificName, String origin, String notes, Blob image) {
        this.id = id;
        this.commonName = commonName;
        this.scientificName = scientificName;
        this.origin = origin;
        this.notes = notes;
        this.image = image;
    }

    /**
     * No-arg constructor for {@link ModifiedStateTracker}. This constructor creates an empty
     * Species object that can be populated with data later. It is protected to ensure that only
     * classes within the same package or subclasses can create instances without providing
     * initial data.
     */
    protected Species() {

    }

    /**
     * Get the species ID
     *
     * @return ID from Database, <= 0 if not yet stored
     */
    public int getID() {
        return id;
    }

    /**
     * Set the species ID
     *
     * @param id ID from the Database
     */
    public void setID(int id) {
        this.id = id;
    }

    /**
     * Get the species common name
     *
     * @return Species common name
     */
    public String getCommonName() {
        return commonName;
    }

    /**
     * Set the species common name
     *
     * @param commonName Species common name
     */
    public void setCommonName(String commonName) {
        this.commonName = commonName;
    }

    /**
     * Get the species scientific name
     *
     * @return Species scientific name
     */
    public String getScientificName() {
        return scientificName;
    }

    /**
     * Set the species scientific name
     *
     * @param scientificName Species scientific name
     */
    public void setScientificName(String scientificName) {
        this.scientificName = scientificName;
    }

    /**
     * Get the species origin
     *
     * @return Species origin
     */
    public String getOrigin() {
        return origin;
    }

    /**
     * Set the species origin
     *
     * @param origin Species origin e.g country
     */
    public void setOrigin(String origin) {
        this.origin = origin;
    }

    /**
     * Get the additional notes
     *
     * @return Additional notes
     */
    public String getNotes() {
        return notes;
    }

    /**
     * Set the additional notes
     *
     * @param notes Additional notes
     */
    public void setNotes(String notes) {
        this.notes = notes;
    }

    /**
     * Get the image of the species.
     *
     * @return A {@link Blob} object representing the species' image, or {@code null} if not available.
     */
    public Blob getImage() {
        return image;
    }

    /**
     * Set the image of the species.
     *
     * @param image A {@link Blob} object representing the species' image.
     *              Can be {@code null} if no image is available.
     */
    public void setImage(Blob image) {
        this.image = image;
    }

    @Override
    public boolean equals(Object obj) {
        return obj instanceof Species && ((Species) obj).id == this.id;
    }
}
