package ru.kirillius.pf.sdn.core.Auth;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import ru.kirillius.json.JSONProperty;
import ru.kirillius.json.JSONSerializable;

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

/**
 * Represents a persistent authentication token with metadata for API access.
 */
@NoArgsConstructor
@JSONSerializable
public class AuthToken {
    /**
     * Creates a token wrapper for the specified raw token string.
     */
    public AuthToken(String token) {
        this.token = token;
    }

    @Setter
    @Getter
    @JSONProperty
    private String description = "untitled";

    /**
     * Tokens are equal when their token strings match.
     */
    @Override
    public boolean equals(Object o) {
        if (o == null || getClass() != o.getClass()) return false;
        AuthToken authToken = (AuthToken) o;
        return Objects.equals(token, authToken.token);
    }

    /**
     * Produces a hash code derived from the token string.
     */
    @Override
    public int hashCode() {
        return Objects.hashCode(token);
    }

    @Setter
    @Getter
    @JSONProperty
    private String token = UUID.randomUUID().toString();
}