import { Model } from '../core/Model.js';
import { exponentialBackoffDelay, shouldRetryApiError, retry } from './retry_logic.js';
export default class InvitationModel extends Model {
    /**
     * A reference to the SDK service used to perform API calls.
     */
    sdk;
    /**
     * Whether the model is currently loading data.
     */
    loading = false;
    constructor(sdk) {
        super();
        this.sdk = sdk;
    }
    /**
     * Fetches the invitation data for the given token.
     * @param token The invitation token to fetch.
     * @returns The invitation data.
     * @throws Error if the invitation cannot be fetched (e.g., network error or invalid token).
     */
    async fetch(token) {
        this.loading = true;
        const operation = async () => {
            return this.sdk.organizations.invitations.findByToken(token);
        };
        const retryOptions = {
            retries: this.retryCount,
            delayMs: exponentialBackoffDelay,
            shouldRetry: shouldRetryApiError,
        };
        try {
            this.raw = await retry(operation, retryOptions);
        }
        finally {
            this.loading = false;
        }
        return this.raw;
    }
    /**
     * Rejects the invitation.
     * @throws Error if the invitation cannot be rejected (e.g., network error).
     */
    async reject() {
        const { value } = this;
        if (!value) {
            throw new Error('Cannot reject invitation without fetching it first.');
        }
        this.loading = true;
        const operation = async () => {
            return this.sdk.organizations.invitations.decline(value.oid, value.token);
        };
        const retryOptions = {
            retries: this.retryCount,
            delayMs: exponentialBackoffDelay,
            shouldRetry: shouldRetryApiError,
        };
        try {
            this.raw = await retry(operation, retryOptions);
        }
        finally {
            this.loading = false;
        }
    }
}
//# sourceMappingURL=InvitationModel.js.map