/*
 * Copyright (c) 2010-2025 Contributors to the openHAB project
 *
 * See the NOTICE file(s) distributed with this work for additional
 * information.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0
 *
 * SPDX-License-Identifier: EPL-2.0
 */
package org.openhab.core.auth;

import java.util.Date;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
 * An API token represents long-term credentials generated by (or for) a user, giving the bearer access for a certain
 * scope on behalf of this user.
 *
 * @author Yannick Schaus - initial contribution
 *
 */
@NonNullByDefault
public class UserApiToken {
    private final String name;
    private final String apiToken;
    private final Date createdTime;
    private final String scope;

    /**
     * Constructs an API token.
     *
     * @param name the name of the token, for identification purposes
     * @param apiToken the serialization of the token
     * @param scope the scope this token is valid for
     */
    public UserApiToken(String name, String apiToken, String scope) {
        this.name = name;
        this.apiToken = apiToken;
        this.createdTime = new Date();
        this.scope = scope;
    }

    /**
     * Gets the name identifying the token
     *
     * @return the API token
     */
    public String getName() {
        return name;
    }

    /**
     * Get the serialization of the opaque API token which can be passed in requests as a "Bearer" token in the
     * Authorization HTTP header.
     *
     * @return the API token
     */
    public String getApiToken() {
        return apiToken;
    }

    /**
     * Gets the time when this token was created.
     *
     * @return the date of creation
     */
    public Date getCreatedTime() {
        return createdTime;
    }

    /**
     * Gets the scope this token is valid for.
     *
     * @return the scope
     */
    public String getScope() {
        return scope;
    }

    @Override
    public String toString() {
        return "name=" + name + ", createdTime=" + createdTime + ", scope=" + scope;
    }
}
