import { OAuthResponseError } from "./util.js";
import { OAuthClientCreateRequestSchema, OAuthClientCreateResponseSchema, OAuthClientDeleteResponseSchema, OAuthClientGetResponseSchema, OAuthClientListResponseSchema, OAuthClientRevokeAllUsersResponseSchema, OAuthClientRevokeUserResponseSchema, OAuthClientRotateSecretResponseSchema, OAuthClientUpdateRequestSchema, OAuthClientUpdateResponseSchema, OAuthClientUsersResponseSchema, } from "./types.js";
export async function oauthClientList(client) {
    const resp = await client.get('/oidc/clients', OAuthClientListResponseSchema);
    if (resp.success) {
        return resp.data;
    }
    throw new OAuthResponseError({ message: resp.message });
}
export async function oauthClientGet(client, id) {
    const resp = await client.get(`/oidc/clients/${encodeURIComponent(id)}`, OAuthClientGetResponseSchema);
    if (resp.success) {
        return resp.data;
    }
    throw new OAuthResponseError({ message: resp.message });
}
export async function oauthClientCreate(client, request) {
    const resp = await client.post('/oidc/clients', request, OAuthClientCreateResponseSchema, OAuthClientCreateRequestSchema);
    if (resp.success) {
        return resp.data;
    }
    throw new OAuthResponseError({ message: resp.message });
}
export async function oauthClientUpdate(client, id, request) {
    const resp = await client.put(`/oidc/clients/${encodeURIComponent(id)}`, request, OAuthClientUpdateResponseSchema, OAuthClientUpdateRequestSchema);
    if (resp.success) {
        return resp.data;
    }
    throw new OAuthResponseError({ message: resp.message });
}
export async function oauthClientDelete(client, id) {
    const resp = await client.delete(`/oidc/clients/${encodeURIComponent(id)}`, OAuthClientDeleteResponseSchema);
    if (resp.success) {
        return resp.data;
    }
    throw new OAuthResponseError({ message: resp.message });
}
export async function oauthClientRotateSecret(client, id) {
    const resp = await client.post(`/oidc/clients/${encodeURIComponent(id)}/rotate-secret`, undefined, OAuthClientRotateSecretResponseSchema);
    if (resp.success) {
        return resp.data;
    }
    throw new OAuthResponseError({ message: resp.message });
}
export async function oauthClientUsers(client, id) {
    const resp = await client.get(`/oidc/clients/${encodeURIComponent(id)}/users`, OAuthClientUsersResponseSchema);
    if (resp.success) {
        return resp.data;
    }
    throw new OAuthResponseError({ message: resp.message });
}
export async function oauthClientRevokeAllUsers(client, id) {
    const resp = await client.delete(`/oidc/clients/${encodeURIComponent(id)}/users`, OAuthClientRevokeAllUsersResponseSchema);
    if (resp.success) {
        return resp.data;
    }
    throw new OAuthResponseError({ message: resp.message });
}
export async function oauthClientRevokeUser(client, id, userId) {
    const resp = await client.delete(`/oidc/clients/${encodeURIComponent(id)}/users/${encodeURIComponent(userId)}`, OAuthClientRevokeUserResponseSchema);
    if (resp.success) {
        return resp.data;
    }
    throw new OAuthResponseError({ message: resp.message });
}
//# sourceMappingURL=clients.js.map