/* tslint:disable */
/* eslint-disable */
/**
 * authentik
 * Making authentication simple.
 *
 * The version of the OpenAPI document: 2026.5.0-rc1
 * Contact: hello@goauthentik.io
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

import type { OAuth2Provider } from "./OAuth2Provider";
import { OAuth2ProviderFromJSON, OAuth2ProviderToJSON } from "./OAuth2Provider";
import type { User } from "./User";
import { UserFromJSON, UserToJSON } from "./User";

/**
 * Serializer for BaseGrantModel and RefreshToken
 * @export
 * @interface TokenModel
 */
export interface TokenModel {
    /**
     *
     * @type {number}
     * @memberof TokenModel
     */
    readonly pk: number;
    /**
     *
     * @type {OAuth2Provider}
     * @memberof TokenModel
     */
    provider: OAuth2Provider;
    /**
     *
     * @type {User}
     * @memberof TokenModel
     */
    user: User;
    /**
     * Check if token is expired yet.
     * @type {boolean}
     * @memberof TokenModel
     */
    readonly isExpired: boolean;
    /**
     *
     * @type {Date}
     * @memberof TokenModel
     */
    expires?: Date | null;
    /**
     *
     * @type {Array<string>}
     * @memberof TokenModel
     */
    scope: Array<string>;
    /**
     * Get the token's id_token as JSON String
     * @type {string}
     * @memberof TokenModel
     */
    readonly idToken: string;
    /**
     *
     * @type {boolean}
     * @memberof TokenModel
     */
    revoked?: boolean;
}

/**
 * Check if a given object implements the TokenModel interface.
 */
export function instanceOfTokenModel(value: object): value is TokenModel {
    if (!("pk" in value) || value["pk"] === undefined) return false;
    if (!("provider" in value) || value["provider"] === undefined) return false;
    if (!("user" in value) || value["user"] === undefined) return false;
    if (!("isExpired" in value) || value["isExpired"] === undefined) return false;
    if (!("scope" in value) || value["scope"] === undefined) return false;
    if (!("idToken" in value) || value["idToken"] === undefined) return false;
    return true;
}

export function TokenModelFromJSON(json: any): TokenModel {
    return TokenModelFromJSONTyped(json, false);
}

export function TokenModelFromJSONTyped(json: any, ignoreDiscriminator: boolean): TokenModel {
    if (json == null) {
        return json;
    }
    return {
        pk: json["pk"],
        provider: OAuth2ProviderFromJSON(json["provider"]),
        user: UserFromJSON(json["user"]),
        isExpired: json["is_expired"],
        expires: json["expires"] == null ? undefined : new Date(json["expires"]),
        scope: json["scope"],
        idToken: json["id_token"],
        revoked: json["revoked"] == null ? undefined : json["revoked"],
    };
}

export function TokenModelToJSON(json: any): TokenModel {
    return TokenModelToJSONTyped(json, false);
}

export function TokenModelToJSONTyped(
    value?: Omit<TokenModel, "pk" | "is_expired" | "id_token"> | null,
    ignoreDiscriminator: boolean = false,
): any {
    if (value == null) {
        return value;
    }

    return {
        provider: OAuth2ProviderToJSON(value["provider"]),
        user: UserToJSON(value["user"]),
        expires: value["expires"] == null ? value["expires"] : value["expires"].toISOString(),
        scope: value["scope"],
        revoked: value["revoked"],
    };
}
