package premium_store.model;

import javax.persistence.*;
import java.util.Objects;

@Entity
@Table(name = "TANKS")
public class Tank {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Column(nullable = false)
    private String name;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "nation")
    private Nation nation;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "tankLevel")
    private TankLevel tankLevel;

    @Column(nullable = false)
    private int cost;

    public Tank() {
    }

    public Tank(String name, Nation nation, TankLevel tankLevel, int cost) {
        this.name = name;
        this.nation = nation;
        this.tankLevel = tankLevel;
        this.cost = cost;
    }

    public Long getId(){
        return id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getCost() {
        return cost;
    }

    public void setCost(int cost) {
        this.cost = cost;
    }

    public TankLevel getLevel() {
        return tankLevel;
    }

    public void setLevel(TankLevel tankLevel) {
        this.tankLevel = tankLevel;
    }

    public Nation getNation() {
        return nation;
    }

    public void setNation(Nation nation) {
        this.nation = nation;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;

        if (!(o instanceof Tank tank)) return false;

        return Objects.equals(getId(), tank.getId()) && Objects.equals(getName(), tank.getName())
                && Objects.equals(getCost(), tank.getCost())
                && Objects.equals(getLevel(), tank.getLevel());
    }

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

    //преобразование данных по объекту в строчку
    @Override
    public String toString() {
        return "Tank{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", nation='" + nation.getNation() + '\'' +
                ", level='" + tankLevel.getLevel() + '\'' +
                ", cost='" + cost + '\'' +
                '}';
    }
}

