package com.insa.app.model;

import com.insa.app.Resources;

import java.util.UUID;

public class User {
    private UUID id;

    private String name;
    private String ipAdress;

    private transient boolean connected;

    private User() {}



    public User(UUID id, String name, String ipAdress) {
        this.id = id;
        this.name = name;
        this.ipAdress = ipAdress;
        this.connected = false;
    }

    public User(UUID id, String name, String ipAdress, boolean connected) {
        this.id = id;
        this.name = name;
        this.ipAdress = ipAdress;
        this.connected = connected;
    }

    public User(String name, String ipAdress) {
        this.name = name;
        this.id = UUID.randomUUID();
        this.ipAdress = ipAdress + ":" + Resources.clientPort;
        this.connected = false;
    }

    public String getName() {
        return name;
    }

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

    public UUID getId() {
        return id;
    }

    public String getIpAddress() {
        return ipAdress;
    }

    public void setIpAdress(String ipAdress) {
        this.ipAdress = ipAdress;
    }

    public void setConnected() {
        this.connected = true;
    }

    public void setDisconnected() {
        this.connected = false;
    }

    @Override
    public String toString() {
        if (connected) {
            return name + "@" + ipAdress + " - ONLINE";
        } else {
            return name + "@" +  ipAdress + " - OFFLINE";
        }
    }

    @Override
    public boolean equals(Object o) {
        if (this == o)
            return true;
        // null check
        if (o == null)
            return false;
        // type check and cast
        if (getClass() != o.getClass())
            return false;
        User u = (User) o;
        return id.equals(u.id);
    }

}
