/*
 *  This file is part of Player Analytics (Plan).
 *
 *  Plan is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License v3 as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Plan is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with Plan. If not, see <https://www.gnu.org/licenses/>.
 */
package com.djrapitops.plan.gathering.domain;

import com.djrapitops.plan.identification.ServerUUID;

import java.util.Objects;
import java.util.UUID;

/**
 * Represents user information stored in plan_user_info.
 * <p>
 * Unlike {@link BaseUser} one instance is stored per server for a single player.
 * Proxy servers are an exception, and UserInfo is not stored for them.
 *
 * @author AuroraLS3
 */
public class UserInfo {

    private final UUID playerUUID;
    private final ServerUUID serverUUID;
    private final long registered;
    private final boolean banned;
    private final boolean opped;
    private final String joinAddress;

    public UserInfo(UUID playerUUID, ServerUUID serverUUID, long registered, boolean opped, String joinAddress, boolean banned) {
        this.playerUUID = playerUUID;
        this.serverUUID = serverUUID;
        this.registered = registered;
        this.opped = opped;
        this.banned = banned;
        this.joinAddress = joinAddress;
    }

    public UUID getPlayerUuid() {
        return playerUUID;
    }

    public ServerUUID getServerUUID() {
        return serverUUID;
    }

    /**
     * @deprecated Join address is now stored in {@link FinishedSession#getExtraData()}, this method may become unreliable in the future.
     */
    @Deprecated(since = "5.4 build 1722")
    public String getJoinAddress() {
        return joinAddress;
    }

    public long getRegistered() {
        return registered;
    }

    public boolean isBanned() {
        return banned;
    }

    public boolean isOperator() {
        return opped;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        UserInfo userInfo = (UserInfo) o;
        return registered == userInfo.registered
                && banned == userInfo.banned
                && opped == userInfo.opped
                && Objects.equals(playerUUID, userInfo.playerUUID)
                && Objects.equals(serverUUID, userInfo.serverUUID)
                && Objects.equals(joinAddress, userInfo.joinAddress);
    }

    @Override
    public int hashCode() {
        return Objects.hash(playerUUID, serverUUID, registered, banned, joinAddress, opped);
    }

    @Override
    public String toString() {
        return "UserInfo{" +
                "playerUUID=" + playerUUID +
                ", serverUUID=" + serverUUID +
                ", registered=" + registered +
                ", banned=" + banned +
                ", opped=" + opped +
                ", joinAddress=" + joinAddress +
                '}';
    }
}