package com.kastle.sharewise.model;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.DateSerializer;

import java.io.Serializable;
import java.util.Date;
import java.util.Objects;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

/**
 * NOTE: This class is to be used passed testing and should not enter release. Will have access blocked when
 * Spring Security added
 *
 * This class is for testing only. A simple basic class with is an Entity. Will be automatically made into a SQL table
 * though SpringBoot if specified to in application.yml.
 * Holds four basic types plus Date (all SQL types), setters and getters, toString, hashcode and equals.
 */
@Entity
public class Greeting implements Serializable {

    /**
     * SQL primary key, autogenerated field. The instance unique identifier.
     */
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "Id")
    Long id;

    /**
     * SQL VARCHAR(32). The name of the greeter.
     */
    @Column(name = "name", length = 32)
    String name;

    /**
     * SQL VARCHAR(32). The email of the greeter.
     */
    @Column(name = "email", length = 32)
    String email;

    /**
     * SQL VARCHAR(64). The password of the greeter.
     * NOTE: This is obviously insecure. This class is only for testing setup, will not reach release.
     */
    @Column(name = "password", length = 64)
    String password;

    /**
     * SQL timestamp
     */
    @JsonSerialize(using = DateSerializer.class)
    @Column(name = "time_stamp")
    Date timeStamp;


    /**
     * @return id
     */
    public Long getId() {
        return id;
    }

    /**
     * @param timeStamp The new Date to set as the timestamp
     */
    public void setTimeStamp(Date timeStamp) {
        this.timeStamp = timeStamp;
    }

    /**
     * @param id The new instance id
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @return The instance's name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name The new string to set as name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return The instance's email
     */
    public String getEmail() {
        return email;
    }

    /**
     * @param email The string to set as the new instance email
     */
    public void setEmail(String email) {
        this.email = email;
    }

    /**
     * @return The instance's email
     */
    public String getPassword() {
        return password;
    }

    /**
     * @param password The String to set as the new password for this instance
     */
    public void setPassword(String password) {
        this.password = password;
    }

    /**
     * @return timestamp
     */
    public Date getTimeStamp() {
        return timeStamp;
    }

    /**
     * @return instance as a String
     */
    @Override
    public String toString() {
        return "Greeting{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", email='" + email + '\'' +
                ", password='" + password + '\'' +
                ", timeStamp=" + timeStamp +
                '}';
    }

    /**
     * @param o another instance of this class
     * @return true if the two instances are equal in content
     */
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Greeting greeting = (Greeting) o;
        return id.equals(greeting.id) &&
                name.equals(greeting.name) &&
                email.equals(greeting.email) &&
                password.equals(greeting.password) &&
                timeStamp.equals(greeting.timeStamp);
    }

    /**
     * @return A hash of the instance
     */
    @Override
    public int hashCode() {
        return Objects.hash(id, name, email, password, timeStamp);
    }
}
