package premium_store.controller.DTO;

import com.fasterxml.jackson.annotation.JsonProperty;
import premium_store.model.GameClient;
import premium_store.model.UserRole;

import java.util.ArrayList;
import java.util.List;

//класс, который соединяет танки клиента в одну строчку (нам так захотелось)
public class ClientDTO {
    private long id;
    private String login;
    private String password;
    private String email;
    private Integer balance;
    private List<TankDTO> tanks;
    private UserRole role;

    public ClientDTO(){ }

    public ClientDTO(GameClient gameClient){
        this.id = gameClient.getId();
        this.login = gameClient.getLogin();
        this.password = gameClient.getPassword();
        this.email = gameClient.getEmail();
        this.balance = gameClient.getBalance();

        if(gameClient.getTanks() != null && gameClient.getTanks().size() > 0){
            this.tanks = gameClient.getTanks().stream()
                    .map(TankDTO::new)
                    .toList();
        }

        this.role = gameClient.getRole();
    }

    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    public long getId(){
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getLogin(){
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    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<TankDTO> getTanks(){
        return tanks;
    }

    public Long getIdLastTanks(){
        if(tanks.size() > 0){
            return tanks.get(tanks.size() - 1).getId();
        } else {
            return null;
        }
    }

    public void setTanks(List<TankDTO> tanks) {
        this.tanks = tanks;
    }

    public UserRole getRole() {
        return role;
    }

    public void setRole(UserRole role) {
        this.role = role;
    }
}
