package premium_store.model;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

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

    @Column(name = "nickName", nullable = false, length = 255)
    private String nickName;

    @Column(name = "email", nullable = false, length = 255)
    private String email;

    @Column(name = "balance")
    private Integer balance;

    @OneToMany(fetch = FetchType.EAGER)
    private List<Tank> tanks = new ArrayList<>();

    public GameClient(){ }

    public GameClient(String nickName, String email, Integer balance){
        this.nickName = nickName;
        this.email = email;
        this.balance = balance;
    }

    public Long getId(){
        return id;
    }

    public String getNickName(){
        return nickName;
    }

    public void setNickName(String nickName){
        this.nickName = nickName;
    }

    public String getEmail(){
        return email;
    }

    public void setEmail(String email){
        this.email = email;
    }

    public Integer getBalance(){
        return balance;
    }

    public void setBalance(Integer balance){
        this.balance = balance;
    }

    public List<Tank> getTanks(){
        return tanks;
    }

    public void setTanks(Tank tank){
        this.tanks.add(tank);
    }

    //метод для сравнения
    @Override
    public boolean equals(Object o) {
        if (this == o)
            return true;

        if (o == null || getClass() != o.getClass())
            return false;

        GameClient gameClient = (GameClient) o;

        return Objects.equals(id, gameClient.id);
    }

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

    //преобразование данных по объекту в строчку
    @Override
    public String toString() {
        return "Client{" +
                "id=" + id +
                ", nickName='" + nickName + '\'' +
                ", email='" + email + '\'' +
                ", balance='" + balance + '\'' +
                ", tanks='" + tanks.stream().map(Object::toString).collect(Collectors.joining(", ")) + '\'' +
                '}';
    }
}

