# Generated by ariadne-codegen
# Source: metasrht/graphql/

from datetime import datetime
from typing import Any, Optional, Union

import httpx
from flask import has_request_context, request
from srht.config import cfg, get_origin
from srht.graphql import InternalAuth

from .base_client import BaseClient
from .base_model import UNSET, UnsetType
from .cancel_subscription import CancelSubscription
from .change_product import ChangeProduct
from .confirm_email_change import ConfirmEmailChange
from .confirm_password_change import ConfirmPasswordChange
from .confirm_registration import ConfirmRegistration
from .create_pgp_key import CreatePGPKey
from .create_renewal_payment_intent import CreateRenewalPaymentIntent
from .create_setup_intent import CreateSetupIntent
from .create_ssh_key import CreateSSHKey
from .delete_pgp_key import DeletePGPKey
from .delete_ssh_key import DeleteSSHKey
from .delete_user import DeleteUser
from .enable_totp import EnableTOTP
from .enums import Currency, PaymentInterval
from .finalize_payment_intent import FinalizePaymentIntent
from .finalize_setup_intent import FinalizeSetupIntent
from .get_billing_address import GetBillingAddress
from .get_billing_dashboard import GetBillingDashboard
from .get_billing_setup import GetBillingSetup
from .get_cancel_parameters import GetCancelParameters
from .get_introspection import GetIntrospection
from .get_invoices import GetInvoices
from .get_o_auth_client import GetOAuthClient
from .get_payment_outcome import GetPaymentOutcome
from .get_product_selection import GetProductSelection
from .get_setup_intent_detail import GetSetupIntentDetail
from .get_subscription_parameters import GetSubscriptionParameters
from .get_user_admin import GetUserAdmin
from .input_types import BillingAddressInput, UserInput
from .issue_auth_code import IssueAuthCode
from .issue_bearer_token import IssueBearerToken
from .issue_pat import IssuePAT
from .o_auth_dashboard import OAuthDashboard
from .order_product import OrderProduct
from .process_payment_due import ProcessPaymentDue
from .refresh_grant import RefreshGrant
from .register_account import RegisterAccount
from .register_client import RegisterClient
from .remove_payment_method import RemovePaymentMethod
from .request_password_reset import RequestPasswordReset
from .reregister_o_auth_client import ReregisterOAuthClient
from .revoke_bearer import RevokeBearer
from .revoke_pat import RevokePAT
from .send_email import SendEmail
from .set_default_payment_method import SetDefaultPaymentMethod
from .subsidize_user import SubsidizeUser
from .transfer_billing_info import TransferBillingInfo
from .unregister_o_auth_client import UnregisterOAuthClient
from .update_billing_address import UpdateBillingAddress
from .update_profile import UpdateProfile


def gql(q: str) -> str:
    return q


class Client(BaseClient):
    def __init__(self, auth=None, headers=None, client=None, **kwargs):
        origin = cfg("meta.sr.ht", "api-origin", default=get_origin("meta.sr.ht"))
        if auth is None:
            auth = InternalAuth()
        headers = {**auth.headers, "User-Agent": "meta.sr.ht frontend"}
        if has_request_context():
            headers["X-Forwarded-For"] = ", ".join(request.access_route)
        if not client:
            backend_timeout = cfg("meta.sr.ht", "backend-timeout", default=3)
            client = httpx.Client(
                headers=headers, timeout=httpx.Timeout(int(backend_timeout))
            )
        super().__init__(origin + "/query", headers, client, **kwargs)

    def get_user_admin(self, **kwargs: Any) -> GetUserAdmin:
        query = gql("""
            query GetUserAdmin {
              personalAccessTokens {
                id
                comment
                issued
                expires
              }
              oauthClients {
                id
                uuid
                name
                url
              }
              oauthGrants {
                id
                issued
                expires
                tokenHash
                client {
                  name
                  url
                  owner {
                    __typename
                    canonicalName
                  }
                }
              }
              user: me {
                subscription {
                  interval
                  subtotal
                  currency
                }
                invoices {
                  results {
                    ...invoice
                  }
                }
              }
            }

            fragment invoice on Invoice {
              id
              invoiceNo
              issued
              serviceEnd
              total
              currency
            }
            """)
        variables: dict[str, object] = {}
        response = self.execute(
            query=query, operation_name="GetUserAdmin", variables=variables, **kwargs
        )
        data = self.get_data(response)
        return GetUserAdmin.model_validate(data)

    def transfer_billing_info(
        self, from_: str, to: str, **kwargs: Any
    ) -> TransferBillingInfo:
        query = gql("""
            mutation TransferBillingInfo($from: String!, $to: String!) {
              user: billingTransfer(from: $from, to: $to) {
                username
              }
            }
            """)
        variables: dict[str, object] = {"from": from_, "to": to}
        response = self.execute(
            query=query,
            operation_name="TransferBillingInfo",
            variables=variables,
            **kwargs
        )
        data = self.get_data(response)
        return TransferBillingInfo.model_validate(data)

    def subsidize_user(self, uid: int, until: datetime, **kwargs: Any) -> SubsidizeUser:
        query = gql("""
            mutation SubsidizeUser($uid: Int!, $until: Time!) {
              user: subsidizeUser(userID: $uid, until: $until) {
                username
              }
            }
            """)
        variables: dict[str, object] = {"uid": uid, "until": until}
        response = self.execute(
            query=query, operation_name="SubsidizeUser", variables=variables, **kwargs
        )
        data = self.get_data(response)
        return SubsidizeUser.model_validate(data)

    def register_account(
        self,
        email: str,
        username: str,
        password: str,
        pgp_key: Union[Optional[str], UnsetType] = UNSET,
        **kwargs: Any
    ) -> RegisterAccount:
        query = gql("""
            mutation RegisterAccount($email: String!, $username: String!, $password: String!, $pgpKey: String) {
              registerAccount(
                email: $email
                username: $username
                password: $password
                pgpKey: $pgpKey
              ) {
                id
              }
            }
            """)
        variables: dict[str, object] = {
            "email": email,
            "username": username,
            "password": password,
            "pgpKey": pgp_key,
        }
        response = self.execute(
            query=query, operation_name="RegisterAccount", variables=variables, **kwargs
        )
        data = self.get_data(response)
        return RegisterAccount.model_validate(data)

    def confirm_registration(self, token: str, **kwargs: Any) -> ConfirmRegistration:
        query = gql("""
            mutation ConfirmRegistration($token: String!) {
              user: confirmRegistration(token: $token) {
                id
              }
            }
            """)
        variables: dict[str, object] = {"token": token}
        response = self.execute(
            query=query,
            operation_name="ConfirmRegistration",
            variables=variables,
            **kwargs
        )
        data = self.get_data(response)
        return ConfirmRegistration.model_validate(data)

    def request_password_reset(self, email: str, **kwargs: Any) -> RequestPasswordReset:
        query = gql("""
            mutation RequestPasswordReset($email: String!) {
              resetPassword(email: $email)
            }
            """)
        variables: dict[str, object] = {"email": email}
        response = self.execute(
            query=query,
            operation_name="RequestPasswordReset",
            variables=variables,
            **kwargs
        )
        data = self.get_data(response)
        return RequestPasswordReset.model_validate(data)

    def confirm_password_change(
        self, token: str, password: str, **kwargs: Any
    ) -> ConfirmPasswordChange:
        query = gql("""
            mutation ConfirmPasswordChange($token: String!, $password: String!) {
              user: confirmPasswordChange(token: $token, newPassword: $password) {
                id
              }
            }
            """)
        variables: dict[str, object] = {"token": token, "password": password}
        response = self.execute(
            query=query,
            operation_name="ConfirmPasswordChange",
            variables=variables,
            **kwargs
        )
        data = self.get_data(response)
        return ConfirmPasswordChange.model_validate(data)

    def get_billing_dashboard(self, **kwargs: Any) -> GetBillingDashboard:
        query = gql("""
            query GetBillingDashboard {
              me {
                subscription {
                  status
                  updated
                  interval
                  autorenew
                  currency
                  subtotal
                  total
                  product {
                    retired
                  }
                  payment {
                    status
                    error
                  }
                }
                methods: paymentMethods {
                  id
                  name
                  created
                  expires
                }
                defaultMethod: defaultPaymentMethod {
                  id
                }
                address: billingAddress {
                  ...billingAddress
                }
                invoices {
                  results {
                    ...invoice
                  }
                }
              }
            }

            fragment billingAddress on BillingAddress {
              fullName
              businessName
              address1
              address2
              city
              region
              postcode
              country
              vat
            }

            fragment invoice on Invoice {
              id
              invoiceNo
              issued
              serviceEnd
              total
              currency
            }
            """)
        variables: dict[str, object] = {}
        response = self.execute(
            query=query,
            operation_name="GetBillingDashboard",
            variables=variables,
            **kwargs
        )
        data = self.get_data(response)
        return GetBillingDashboard.model_validate(data)

    def get_billing_address(self, **kwargs: Any) -> GetBillingAddress:
        query = gql("""
            query GetBillingAddress {
              me {
                billingAddress {
                  ...billingAddress
                }
              }
            }

            fragment billingAddress on BillingAddress {
              fullName
              businessName
              address1
              address2
              city
              region
              postcode
              country
              vat
            }
            """)
        variables: dict[str, object] = {}
        response = self.execute(
            query=query,
            operation_name="GetBillingAddress",
            variables=variables,
            **kwargs
        )
        data = self.get_data(response)
        return GetBillingAddress.model_validate(data)

    def update_billing_address(
        self, address: BillingAddressInput, **kwargs: Any
    ) -> UpdateBillingAddress:
        query = gql("""
            mutation UpdateBillingAddress($address: BillingAddressInput!) {
              updateBillingAddress(input: $address) {
                country
              }
            }
            """)
        variables: dict[str, object] = {"address": address}
        response = self.execute(
            query=query,
            operation_name="UpdateBillingAddress",
            variables=variables,
            **kwargs
        )
        data = self.get_data(response)
        return UpdateBillingAddress.model_validate(data)

    def get_billing_setup(self, **kwargs: Any) -> GetBillingSetup:
        query = gql("""
            query GetBillingSetup {
              products {
                ...product
              }
              user: me {
                paymentDue
                paymentStatus
                invoices {
                  results {
                    id
                  }
                }
                billingAddress {
                  ...billingAddress
                }
              }
            }

            fragment billingAddress on BillingAddress {
              fullName
              businessName
              address1
              address2
              city
              region
              postcode
              country
              vat
            }

            fragment product on Product {
              id
              name
              subsidized
              prices {
                currency
                amount
              }
            }
            """)
        variables: dict[str, object] = {}
        response = self.execute(
            query=query, operation_name="GetBillingSetup", variables=variables, **kwargs
        )
        data = self.get_data(response)
        return GetBillingSetup.model_validate(data)

    def order_product(
        self,
        product_id: int,
        currency: Currency,
        address: BillingAddressInput,
        interval: PaymentInterval,
        idempotency_key: Union[Optional[str], UnsetType] = UNSET,
        **kwargs: Any
    ) -> OrderProduct:
        query = gql("""
            mutation OrderProduct($productID: Int!, $currency: Currency!, $address: BillingAddressInput!, $interval: PaymentInterval!, $idempotencyKey: String) {
              intent: orderProductSubscription(
                productID: $productID
                currency: $currency
                address: $address
                interval: $interval
                idempotencyKey: $idempotencyKey
                autorenew: true
              ) {
                __typename
                ...paymentIntent
              }
            }

            fragment billingAddress on BillingAddress {
              fullName
              businessName
              address1
              address2
              city
              region
              postcode
              country
              vat
            }

            fragment paymentIntent on PaymentIntent {
              subscription {
                user {
                  paymentStatus
                }
                currency
                interval
                product {
                  id
                  name
                }
                price {
                  currency
                  amount
                }
                subtotal
              }
              billingAddress {
                ...billingAddress
              }
              idempotencyKey
              taxRate
              taxDue
              totalDue
              ... on StripePaymentIntent {
                publicKey
                clientSecret
              }
            }
            """)
        variables: dict[str, object] = {
            "productID": product_id,
            "currency": currency,
            "address": address,
            "interval": interval,
            "idempotencyKey": idempotency_key,
        }
        response = self.execute(
            query=query, operation_name="OrderProduct", variables=variables, **kwargs
        )
        data = self.get_data(response)
        return OrderProduct.model_validate(data)

    def finalize_payment_intent(
        self, intent_id: str, **kwargs: Any
    ) -> FinalizePaymentIntent:
        query = gql("""
            mutation FinalizePaymentIntent($intentID: String!) {
              intent: finalizePaymentIntent(intentID: $intentID) {
                __typename
                id
                outcome {
                  status
                  error
                }
              }
            }
            """)
        variables: dict[str, object] = {"intentID": intent_id}
        response = self.execute(
            query=query,
            operation_name="FinalizePaymentIntent",
            variables=variables,
            **kwargs
        )
        data = self.get_data(response)
        return FinalizePaymentIntent.model_validate(data)

    def get_payment_outcome(self, **kwargs: Any) -> GetPaymentOutcome:
        query = gql("""
            query GetPaymentOutcome {
              me {
                subscription {
                  payment {
                    status
                    error
                  }
                }
              }
            }
            """)
        variables: dict[str, object] = {}
        response = self.execute(
            query=query,
            operation_name="GetPaymentOutcome",
            variables=variables,
            **kwargs
        )
        data = self.get_data(response)
        return GetPaymentOutcome.model_validate(data)

    def get_setup_intent_detail(self, **kwargs: Any) -> GetSetupIntentDetail:
        query = gql("""
            query GetSetupIntentDetail {
              me {
                paymentStatus
                subscription {
                  id
                  autorenew
                  currency
                  interval
                  subtotal
                  product {
                    name
                  }
                  price {
                    currency
                    amount
                  }
                }
                billingAddress {
                  ...billingAddress
                }
              }
            }

            fragment billingAddress on BillingAddress {
              fullName
              businessName
              address1
              address2
              city
              region
              postcode
              country
              vat
            }
            """)
        variables: dict[str, object] = {}
        response = self.execute(
            query=query,
            operation_name="GetSetupIntentDetail",
            variables=variables,
            **kwargs
        )
        data = self.get_data(response)
        return GetSetupIntentDetail.model_validate(data)

    def create_setup_intent(self, **kwargs: Any) -> CreateSetupIntent:
        query = gql("""
            mutation CreateSetupIntent {
              intent: createSetupIntent {
                __typename
                id
                ... on StripeSetupIntent {
                  publicKey
                  clientSecret
                }
              }
            }
            """)
        variables: dict[str, object] = {}
        response = self.execute(
            query=query,
            operation_name="CreateSetupIntent",
            variables=variables,
            **kwargs
        )
        data = self.get_data(response)
        return CreateSetupIntent.model_validate(data)

    def create_renewal_payment_intent(
        self,
        subscription_id: int,
        idempotency_key: Union[Optional[str], UnsetType] = UNSET,
        **kwargs: Any
    ) -> CreateRenewalPaymentIntent:
        query = gql("""
            mutation CreateRenewalPaymentIntent($subscriptionID: Int!, $idempotencyKey: String) {
              intent: beginSubscriptionRenewal(
                subscriptionID: $subscriptionID
                idempotencyKey: $idempotencyKey
              ) {
                __typename
                ...paymentIntent
              }
            }

            fragment billingAddress on BillingAddress {
              fullName
              businessName
              address1
              address2
              city
              region
              postcode
              country
              vat
            }

            fragment paymentIntent on PaymentIntent {
              subscription {
                user {
                  paymentStatus
                }
                currency
                interval
                product {
                  id
                  name
                }
                price {
                  currency
                  amount
                }
                subtotal
              }
              billingAddress {
                ...billingAddress
              }
              idempotencyKey
              taxRate
              taxDue
              totalDue
              ... on StripePaymentIntent {
                publicKey
                clientSecret
              }
            }
            """)
        variables: dict[str, object] = {
            "subscriptionID": subscription_id,
            "idempotencyKey": idempotency_key,
        }
        response = self.execute(
            query=query,
            operation_name="CreateRenewalPaymentIntent",
            variables=variables,
            **kwargs
        )
        data = self.get_data(response)
        return CreateRenewalPaymentIntent.model_validate(data)

    def finalize_setup_intent(
        self, intent_id: str, **kwargs: Any
    ) -> FinalizeSetupIntent:
        query = gql("""
            mutation FinalizeSetupIntent($intentID: String!) {
              result: finalizeSetupIntent(intentID: $intentID) {
                __typename
                status
              }
            }
            """)
        variables: dict[str, object] = {"intentID": intent_id}
        response = self.execute(
            query=query,
            operation_name="FinalizeSetupIntent",
            variables=variables,
            **kwargs
        )
        data = self.get_data(response)
        return FinalizeSetupIntent.model_validate(data)

    def remove_payment_method(
        self, method_id: int, **kwargs: Any
    ) -> RemovePaymentMethod:
        query = gql("""
            mutation RemovePaymentMethod($methodID: Int!) {
              deletePaymentMethod(id: $methodID) {
                id
              }
            }
            """)
        variables: dict[str, object] = {"methodID": method_id}
        response = self.execute(
            query=query,
            operation_name="RemovePaymentMethod",
            variables=variables,
            **kwargs
        )
        data = self.get_data(response)
        return RemovePaymentMethod.model_validate(data)

    def set_default_payment_method(
        self, method_id: int, **kwargs: Any
    ) -> SetDefaultPaymentMethod:
        query = gql("""
            mutation SetDefaultPaymentMethod($methodID: Int!) {
              setDefaultPaymentMethod(id: $methodID) {
                id
              }
            }
            """)
        variables: dict[str, object] = {"methodID": method_id}
        response = self.execute(
            query=query,
            operation_name="SetDefaultPaymentMethod",
            variables=variables,
            **kwargs
        )
        data = self.get_data(response)
        return SetDefaultPaymentMethod.model_validate(data)

    def get_product_selection(self, **kwargs: Any) -> GetProductSelection:
        query = gql("""
            query GetProductSelection {
              me {
                paymentStatus
                paymentDue
                subscription {
                  autorenew
                  currency
                  status
                  updated
                  product {
                    retired
                  }
                }
              }
              products {
                ...product
              }
            }

            fragment product on Product {
              id
              name
              subsidized
              prices {
                currency
                amount
              }
            }
            """)
        variables: dict[str, object] = {}
        response = self.execute(
            query=query,
            operation_name="GetProductSelection",
            variables=variables,
            **kwargs
        )
        data = self.get_data(response)
        return GetProductSelection.model_validate(data)

    def change_product(
        self, sub_id: int, product_id: int, interval: PaymentInterval, **kwargs: Any
    ) -> ChangeProduct:
        query = gql("""
            mutation ChangeProduct($subID: Int!, $productID: Int!, $interval: PaymentInterval!) {
              updateBillingSubscription(
                subscriptionID: $subID
                input: {productID: $productID, interval: $interval}
              ) {
                id
              }
            }
            """)
        variables: dict[str, object] = {
            "subID": sub_id,
            "productID": product_id,
            "interval": interval,
        }
        response = self.execute(
            query=query, operation_name="ChangeProduct", variables=variables, **kwargs
        )
        data = self.get_data(response)
        return ChangeProduct.model_validate(data)

    def get_cancel_parameters(self, **kwargs: Any) -> GetCancelParameters:
        query = gql("""
            query GetCancelParameters {
              me {
                paymentStatus
                paymentDue
                subscription {
                  status
                  updated
                  product {
                    retired
                  }
                }
              }
            }
            """)
        variables: dict[str, object] = {}
        response = self.execute(
            query=query,
            operation_name="GetCancelParameters",
            variables=variables,
            **kwargs
        )
        data = self.get_data(response)
        return GetCancelParameters.model_validate(data)

    def cancel_subscription(
        self, subscription_id: int, **kwargs: Any
    ) -> CancelSubscription:
        query = gql("""
            mutation CancelSubscription($subscriptionID: Int!) {
              cancelBillingSubscription(subscriptionID: $subscriptionID) {
                id
              }
            }
            """)
        variables: dict[str, object] = {"subscriptionID": subscription_id}
        response = self.execute(
            query=query,
            operation_name="CancelSubscription",
            variables=variables,
            **kwargs
        )
        data = self.get_data(response)
        return CancelSubscription.model_validate(data)

    def get_invoices(
        self, cursor: Union[Optional[Any], UnsetType] = UNSET, **kwargs: Any
    ) -> GetInvoices:
        query = gql("""
            query GetInvoices($cursor: Cursor) {
              me {
                invoices(cursor: $cursor) {
                  cursor
                  results {
                    ...invoice
                  }
                }
              }
            }

            fragment invoice on Invoice {
              id
              invoiceNo
              issued
              serviceEnd
              total
              currency
            }
            """)
        variables: dict[str, object] = {"cursor": cursor}
        response = self.execute(
            query=query, operation_name="GetInvoices", variables=variables, **kwargs
        )
        data = self.get_data(response)
        return GetInvoices.model_validate(data)

    def process_payment_due(self, **kwargs: Any) -> ProcessPaymentDue:
        query = gql("""
            mutation ProcessPaymentDue {
              intent: processPaymentDue {
                __typename
                id
                outcome {
                  status
                  error
                }
              }
            }
            """)
        variables: dict[str, object] = {}
        response = self.execute(
            query=query,
            operation_name="ProcessPaymentDue",
            variables=variables,
            **kwargs
        )
        data = self.get_data(response)
        return ProcessPaymentDue.model_validate(data)

    def get_subscription_parameters(self, **kwargs: Any) -> GetSubscriptionParameters:
        query = gql("""
            query GetSubscriptionParameters {
              me {
                paymentStatus
                paymentDue
                subscription {
                  id
                }
              }
            }
            """)
        variables: dict[str, object] = {}
        response = self.execute(
            query=query,
            operation_name="GetSubscriptionParameters",
            variables=variables,
            **kwargs
        )
        data = self.get_data(response)
        return GetSubscriptionParameters.model_validate(data)

    def send_email(self, address: str, msg: str, **kwargs: Any) -> SendEmail:
        query = gql("""
            mutation SendEmail($address: String!, $msg: String!) {
              sendEmail(address: $address, message: $msg)
            }
            """)
        variables: dict[str, object] = {"address": address, "msg": msg}
        response = self.execute(
            query=query, operation_name="SendEmail", variables=variables, **kwargs
        )
        data = self.get_data(response)
        return SendEmail.model_validate(data)

    def create_ssh_key(self, key: str, **kwargs: Any) -> CreateSSHKey:
        query = gql("""
            mutation CreateSSHKey($key: String!) {
              key: createSSHKey(key: $key) {
                id
              }
            }
            """)
        variables: dict[str, object] = {"key": key}
        response = self.execute(
            query=query, operation_name="CreateSSHKey", variables=variables, **kwargs
        )
        data = self.get_data(response)
        return CreateSSHKey.model_validate(data)

    def delete_ssh_key(self, key: int, **kwargs: Any) -> DeleteSSHKey:
        query = gql("""
            mutation DeleteSSHKey($key: Int!) {
              deleteSSHKey(id: $key) {
                id
              }
            }
            """)
        variables: dict[str, object] = {"key": key}
        response = self.execute(
            query=query, operation_name="DeleteSSHKey", variables=variables, **kwargs
        )
        data = self.get_data(response)
        return DeleteSSHKey.model_validate(data)

    def create_pgp_key(self, key: str, **kwargs: Any) -> CreatePGPKey:
        query = gql("""
            mutation CreatePGPKey($key: String!) {
              createPGPKey(key: $key) {
                id
              }
            }
            """)
        variables: dict[str, object] = {"key": key}
        response = self.execute(
            query=query, operation_name="CreatePGPKey", variables=variables, **kwargs
        )
        data = self.get_data(response)
        return CreatePGPKey.model_validate(data)

    def delete_pgp_key(self, key: int, **kwargs: Any) -> DeletePGPKey:
        query = gql("""
            mutation DeletePGPKey($key: Int!) {
              deletePGPKey(id: $key) {
                id
              }
            }
            """)
        variables: dict[str, object] = {"key": key}
        response = self.execute(
            query=query, operation_name="DeletePGPKey", variables=variables, **kwargs
        )
        data = self.get_data(response)
        return DeletePGPKey.model_validate(data)

    def o_auth_dashboard(self, **kwargs: Any) -> OAuthDashboard:
        query = gql("""
            query OAuthDashboard {
              personalAccessTokens {
                id
                comment
                issued
                expires
              }
              oauthClients {
                id
                uuid
                name
                url
              }
              oauthGrants {
                id
                issued
                expires
                tokenHash
                client {
                  name
                  url
                  owner {
                    __typename
                    canonicalName
                  }
                }
              }
            }
            """)
        variables: dict[str, object] = {}
        response = self.execute(
            query=query, operation_name="OAuthDashboard", variables=variables, **kwargs
        )
        data = self.get_data(response)
        return OAuthDashboard.model_validate(data)

    def issue_pat(
        self,
        grants: Union[Optional[str], UnsetType] = UNSET,
        comment: Union[Optional[str], UnsetType] = UNSET,
        **kwargs: Any
    ) -> IssuePAT:
        query = gql("""
            mutation IssuePAT($grants: String, $comment: String) {
              token: issuePersonalAccessToken(grants: $grants, comment: $comment) {
                secret
                token {
                  expires
                }
              }
            }
            """)
        variables: dict[str, object] = {"grants": grants, "comment": comment}
        response = self.execute(
            query=query, operation_name="IssuePAT", variables=variables, **kwargs
        )
        data = self.get_data(response)
        return IssuePAT.model_validate(data)

    def revoke_pat(self, token_id: int, **kwargs: Any) -> RevokePAT:
        query = gql("""
            mutation RevokePAT($token_id: Int!) {
              revokePersonalAccessToken(id: $token_id) {
                id
              }
            }
            """)
        variables: dict[str, object] = {"token_id": token_id}
        response = self.execute(
            query=query, operation_name="RevokePAT", variables=variables, **kwargs
        )
        data = self.get_data(response)
        return RevokePAT.model_validate(data)

    def revoke_bearer(self, token_hash: str, **kwargs: Any) -> RevokeBearer:
        query = gql("""
            mutation RevokeBearer($token_hash: String!) {
              revokeOAuthGrant(hash: $token_hash) {
                id
              }
            }
            """)
        variables: dict[str, object] = {"token_hash": token_hash}
        response = self.execute(
            query=query, operation_name="RevokeBearer", variables=variables, **kwargs
        )
        data = self.get_data(response)
        return RevokeBearer.model_validate(data)

    def register_client(
        self,
        client_name: str,
        redirect_uri: str,
        client_description: Union[Optional[str], UnsetType] = UNSET,
        client_url: Union[Optional[str], UnsetType] = UNSET,
        **kwargs: Any
    ) -> RegisterClient:
        query = gql("""
            mutation RegisterClient($client_name: String!, $client_description: String, $client_url: String, $redirect_uri: String!) {
              registration: registerOAuthClient(
                redirectUri: $redirect_uri
                clientName: $client_name
                clientDescription: $client_description
                clientUrl: $client_url
              ) {
                ...clientRegistration
              }
            }

            fragment clientRegistration on OAuthClientRegistration {
              client {
                uuid
              }
              secret
            }
            """)
        variables: dict[str, object] = {
            "client_name": client_name,
            "client_description": client_description,
            "client_url": client_url,
            "redirect_uri": redirect_uri,
        }
        response = self.execute(
            query=query, operation_name="RegisterClient", variables=variables, **kwargs
        )
        data = self.get_data(response)
        return RegisterClient.model_validate(data)

    def get_o_auth_client(self, uuid: str, **kwargs: Any) -> GetOAuthClient:
        query = gql("""
            query GetOAuthClient($uuid: String!) {
              client: oauthClientByUUID(uuid: $uuid) {
                description
                name
                redirectUrl
                url
                uuid
                owner {
                  __typename
                  canonicalName
                  ... on User {
                    username
                  }
                }
              }
            }
            """)
        variables: dict[str, object] = {"uuid": uuid}
        response = self.execute(
            query=query, operation_name="GetOAuthClient", variables=variables, **kwargs
        )
        data = self.get_data(response)
        return GetOAuthClient.model_validate(data)

    def reregister_o_auth_client(
        self,
        uuid: str,
        client_name: str,
        redirect_uri: str,
        client_description: Union[Optional[str], UnsetType] = UNSET,
        client_url: Union[Optional[str], UnsetType] = UNSET,
        **kwargs: Any
    ) -> ReregisterOAuthClient:
        query = gql("""
            mutation ReregisterOAuthClient($uuid: String!, $client_name: String!, $client_description: String, $client_url: String, $redirect_uri: String!) {
              revocation: revokeOAuthClient(uuid: $uuid) {
                id
              }
              registration: registerOAuthClient(
                redirectUri: $redirect_uri
                clientName: $client_name
                clientDescription: $client_description
                clientUrl: $client_url
              ) {
                ...clientRegistration
              }
            }

            fragment clientRegistration on OAuthClientRegistration {
              client {
                uuid
              }
              secret
            }
            """)
        variables: dict[str, object] = {
            "uuid": uuid,
            "client_name": client_name,
            "client_description": client_description,
            "client_url": client_url,
            "redirect_uri": redirect_uri,
        }
        response = self.execute(
            query=query,
            operation_name="ReregisterOAuthClient",
            variables=variables,
            **kwargs
        )
        data = self.get_data(response)
        return ReregisterOAuthClient.model_validate(data)

    def unregister_o_auth_client(
        self, uuid: str, **kwargs: Any
    ) -> UnregisterOAuthClient:
        query = gql("""
            mutation UnregisterOAuthClient($uuid: String!) {
              revokeOAuthClient(uuid: $uuid) {
                id
              }
            }
            """)
        variables: dict[str, object] = {"uuid": uuid}
        response = self.execute(
            query=query,
            operation_name="UnregisterOAuthClient",
            variables=variables,
            **kwargs
        )
        data = self.get_data(response)
        return UnregisterOAuthClient.model_validate(data)

    def issue_auth_code(
        self, client_uuid: str, grants: str, **kwargs: Any
    ) -> IssueAuthCode:
        query = gql("""
            mutation IssueAuthCode($client_uuid: String!, $grants: String!) {
              code: issueAuthorizationCode(clientUUID: $client_uuid, grants: $grants)
            }
            """)
        variables: dict[str, object] = {"client_uuid": client_uuid, "grants": grants}
        response = self.execute(
            query=query, operation_name="IssueAuthCode", variables=variables, **kwargs
        )
        data = self.get_data(response)
        return IssueAuthCode.model_validate(data)

    def issue_bearer_token(
        self,
        authorization: str,
        client_uuid: str,
        client_secret: str,
        redirect_uri: Union[Optional[str], UnsetType] = UNSET,
        **kwargs: Any
    ) -> IssueBearerToken:
        query = gql("""
            mutation IssueBearerToken($authorization: String!, $client_uuid: String!, $client_secret: String!, $redirect_uri: String) {
              grant: issueOAuthGrant(
                authorization: $authorization
                clientUUID: $client_uuid
                clientSecret: $client_secret
                redirectUri: $redirect_uri
              ) {
                ...oauthGrant
              }
            }

            fragment oauthGrant on OAuthGrantRegistration {
              grant {
                expires
              }
              grants
              secret
              refreshToken
            }
            """)
        variables: dict[str, object] = {
            "authorization": authorization,
            "client_uuid": client_uuid,
            "client_secret": client_secret,
            "redirect_uri": redirect_uri,
        }
        response = self.execute(
            query=query,
            operation_name="IssueBearerToken",
            variables=variables,
            **kwargs
        )
        data = self.get_data(response)
        return IssueBearerToken.model_validate(data)

    def refresh_grant(
        self,
        refresh_token: str,
        client_uuid: str,
        client_secret: str,
        scope: Union[Optional[str], UnsetType] = UNSET,
        **kwargs: Any
    ) -> RefreshGrant:
        query = gql("""
            mutation RefreshGrant($refresh_token: String!, $client_uuid: String!, $client_secret: String!, $scope: String) {
              grant: refreshOAuthGrant(
                refreshToken: $refresh_token
                clientUUID: $client_uuid
                clientSecret: $client_secret
                grants: $scope
              ) {
                ...oauthGrant
              }
            }

            fragment oauthGrant on OAuthGrantRegistration {
              grant {
                expires
              }
              grants
              secret
              refreshToken
            }
            """)
        variables: dict[str, object] = {
            "refresh_token": refresh_token,
            "client_uuid": client_uuid,
            "client_secret": client_secret,
            "scope": scope,
        }
        response = self.execute(
            query=query, operation_name="RefreshGrant", variables=variables, **kwargs
        )
        data = self.get_data(response)
        return RefreshGrant.model_validate(data)

    def get_introspection(self, **kwargs: Any) -> GetIntrospection:
        query = gql("""
            query GetIntrospection {
              user: me {
                username
              }
              grant: myOauthGrant {
                client {
                  uuid
                }
                issued
                expires
                grants
              }
            }
            """)
        variables: dict[str, object] = {}
        response = self.execute(
            query=query,
            operation_name="GetIntrospection",
            variables=variables,
            **kwargs
        )
        data = self.get_data(response)
        return GetIntrospection.model_validate(data)

    def update_profile(self, input: UserInput, **kwargs: Any) -> UpdateProfile:
        query = gql("""
            mutation UpdateProfile($input: UserInput!) {
              updateUser(input: $input) {
                id
                email
              }
            }
            """)
        variables: dict[str, object] = {"input": input}
        response = self.execute(
            query=query, operation_name="UpdateProfile", variables=variables, **kwargs
        )
        data = self.get_data(response)
        return UpdateProfile.model_validate(data)

    def confirm_email_change(self, token: str, **kwargs: Any) -> ConfirmEmailChange:
        query = gql("""
            mutation ConfirmEmailChange($token: String!) {
              user: confirmEmailChange(token: $token) {
                id
              }
            }
            """)
        variables: dict[str, object] = {"token": token}
        response = self.execute(
            query=query,
            operation_name="ConfirmEmailChange",
            variables=variables,
            **kwargs
        )
        data = self.get_data(response)
        return ConfirmEmailChange.model_validate(data)

    def delete_user(self, reserve: bool, **kwargs: Any) -> DeleteUser:
        query = gql("""
            mutation DeleteUser($reserve: Boolean!) {
              deleteUser(reserve: $reserve)
            }
            """)
        variables: dict[str, object] = {"reserve": reserve}
        response = self.execute(
            query=query, operation_name="DeleteUser", variables=variables, **kwargs
        )
        data = self.get_data(response)
        return DeleteUser.model_validate(data)

    def enable_totp(self, secret: str, **kwargs: Any) -> EnableTOTP:
        query = gql("""
            mutation EnableTOTP($secret: String!) {
              config: enableTOTP(secret: $secret) {
                recoveryCodes
              }
            }
            """)
        variables: dict[str, object] = {"secret": secret}
        response = self.execute(
            query=query, operation_name="EnableTOTP", variables=variables, **kwargs
        )
        data = self.get_data(response)
        return EnableTOTP.model_validate(data)

    get_user_admin_query = "query GetUserAdmin {\n  personalAccessTokens {\n    id\n    comment\n    issued\n    expires\n  }\n  oauthClients {\n    id\n    uuid\n    name\n    url\n  }\n  oauthGrants {\n    id\n    issued\n    expires\n    tokenHash\n    client {\n      name\n      url\n      owner {\n        __typename\n        canonicalName\n      }\n    }\n  }\n  user: me {\n    subscription {\n      interval\n      subtotal\n      currency\n    }\n    invoices {\n      results {\n        ...invoice\n      }\n    }\n  }\n}"
    transfer_billing_info_query = "mutation TransferBillingInfo($from: String!, $to: String!) {\n  user: billingTransfer(from: $from, to: $to) {\n    username\n  }\n}"
    subsidize_user_query = "mutation SubsidizeUser($uid: Int!, $until: Time!) {\n  user: subsidizeUser(userID: $uid, until: $until) {\n    username\n  }\n}"
    register_account_query = "mutation RegisterAccount($email: String!, $username: String!, $password: String!, $pgpKey: String) {\n  registerAccount(\n    email: $email\n    username: $username\n    password: $password\n    pgpKey: $pgpKey\n  ) {\n    id\n  }\n}"
    confirm_registration_query = "mutation ConfirmRegistration($token: String!) {\n  user: confirmRegistration(token: $token) {\n    id\n  }\n}"
    request_password_reset_query = "mutation RequestPasswordReset($email: String!) {\n  resetPassword(email: $email)\n}"
    confirm_password_change_query = "mutation ConfirmPasswordChange($token: String!, $password: String!) {\n  user: confirmPasswordChange(token: $token, newPassword: $password) {\n    id\n  }\n}"
    get_billing_dashboard_query = "query GetBillingDashboard {\n  me {\n    subscription {\n      status\n      updated\n      interval\n      autorenew\n      currency\n      subtotal\n      total\n      product {\n        retired\n      }\n      payment {\n        status\n        error\n      }\n    }\n    methods: paymentMethods {\n      id\n      name\n      created\n      expires\n    }\n    defaultMethod: defaultPaymentMethod {\n      id\n    }\n    address: billingAddress {\n      ...billingAddress\n    }\n    invoices {\n      results {\n        ...invoice\n      }\n    }\n  }\n}"
    get_billing_address_query = "query GetBillingAddress {\n  me {\n    billingAddress {\n      ...billingAddress\n    }\n  }\n}"
    update_billing_address_query = "mutation UpdateBillingAddress($address: BillingAddressInput!) {\n  updateBillingAddress(input: $address) {\n    country\n  }\n}"
    get_billing_setup_query = "query GetBillingSetup {\n  products {\n    ...product\n  }\n  user: me {\n    paymentDue\n    paymentStatus\n    invoices {\n      results {\n        id\n      }\n    }\n    billingAddress {\n      ...billingAddress\n    }\n  }\n}"
    order_product_query = "mutation OrderProduct($productID: Int!, $currency: Currency!, $address: BillingAddressInput!, $interval: PaymentInterval!, $idempotencyKey: String) {\n  intent: orderProductSubscription(\n    productID: $productID\n    currency: $currency\n    address: $address\n    interval: $interval\n    idempotencyKey: $idempotencyKey\n    autorenew: true\n  ) {\n    __typename\n    ...paymentIntent\n  }\n}"
    finalize_payment_intent_query = "mutation FinalizePaymentIntent($intentID: String!) {\n  intent: finalizePaymentIntent(intentID: $intentID) {\n    __typename\n    id\n    outcome {\n      status\n      error\n    }\n  }\n}"
    get_payment_outcome_query = "query GetPaymentOutcome {\n  me {\n    subscription {\n      payment {\n        status\n        error\n      }\n    }\n  }\n}"
    get_setup_intent_detail_query = "query GetSetupIntentDetail {\n  me {\n    paymentStatus\n    subscription {\n      id\n      autorenew\n      currency\n      interval\n      subtotal\n      product {\n        name\n      }\n      price {\n        currency\n        amount\n      }\n    }\n    billingAddress {\n      ...billingAddress\n    }\n  }\n}"
    create_setup_intent_query = "mutation CreateSetupIntent {\n  intent: createSetupIntent {\n    __typename\n    id\n    ... on StripeSetupIntent {\n      publicKey\n      clientSecret\n    }\n  }\n}"
    create_renewal_payment_intent_query = "mutation CreateRenewalPaymentIntent($subscriptionID: Int!, $idempotencyKey: String) {\n  intent: beginSubscriptionRenewal(\n    subscriptionID: $subscriptionID\n    idempotencyKey: $idempotencyKey\n  ) {\n    __typename\n    ...paymentIntent\n  }\n}"
    finalize_setup_intent_query = "mutation FinalizeSetupIntent($intentID: String!) {\n  result: finalizeSetupIntent(intentID: $intentID) {\n    __typename\n    status\n  }\n}"
    remove_payment_method_query = "mutation RemovePaymentMethod($methodID: Int!) {\n  deletePaymentMethod(id: $methodID) {\n    id\n  }\n}"
    set_default_payment_method_query = "mutation SetDefaultPaymentMethod($methodID: Int!) {\n  setDefaultPaymentMethod(id: $methodID) {\n    id\n  }\n}"
    get_product_selection_query = "query GetProductSelection {\n  me {\n    paymentStatus\n    paymentDue\n    subscription {\n      autorenew\n      currency\n      status\n      updated\n      product {\n        retired\n      }\n    }\n  }\n  products {\n    ...product\n  }\n}"
    change_product_query = "mutation ChangeProduct($subID: Int!, $productID: Int!, $interval: PaymentInterval!) {\n  updateBillingSubscription(\n    subscriptionID: $subID\n    input: {productID: $productID, interval: $interval}\n  ) {\n    id\n  }\n}"
    get_cancel_parameters_query = "query GetCancelParameters {\n  me {\n    paymentStatus\n    paymentDue\n    subscription {\n      status\n      updated\n      product {\n        retired\n      }\n    }\n  }\n}"
    cancel_subscription_query = "mutation CancelSubscription($subscriptionID: Int!) {\n  cancelBillingSubscription(subscriptionID: $subscriptionID) {\n    id\n  }\n}"
    get_invoices_query = "query GetInvoices($cursor: Cursor) {\n  me {\n    invoices(cursor: $cursor) {\n      cursor\n      results {\n        ...invoice\n      }\n    }\n  }\n}"
    process_payment_due_query = "mutation ProcessPaymentDue {\n  intent: processPaymentDue {\n    __typename\n    id\n    outcome {\n      status\n      error\n    }\n  }\n}"
    get_subscription_parameters_query = "query GetSubscriptionParameters {\n  me {\n    paymentStatus\n    paymentDue\n    subscription {\n      id\n    }\n  }\n}"
    send_email_query = "mutation SendEmail($address: String!, $msg: String!) {\n  sendEmail(address: $address, message: $msg)\n}"
    create_ssh_key_query = "mutation CreateSSHKey($key: String!) {\n  key: createSSHKey(key: $key) {\n    id\n  }\n}"
    delete_ssh_key_query = "mutation DeleteSSHKey($key: Int!) {\n  deleteSSHKey(id: $key) {\n    id\n  }\n}"
    create_pgp_key_query = "mutation CreatePGPKey($key: String!) {\n  createPGPKey(key: $key) {\n    id\n  }\n}"
    delete_pgp_key_query = "mutation DeletePGPKey($key: Int!) {\n  deletePGPKey(id: $key) {\n    id\n  }\n}"
    o_auth_dashboard_query = "query OAuthDashboard {\n  personalAccessTokens {\n    id\n    comment\n    issued\n    expires\n  }\n  oauthClients {\n    id\n    uuid\n    name\n    url\n  }\n  oauthGrants {\n    id\n    issued\n    expires\n    tokenHash\n    client {\n      name\n      url\n      owner {\n        __typename\n        canonicalName\n      }\n    }\n  }\n}"
    issue_pat_query = "mutation IssuePAT($grants: String, $comment: String) {\n  token: issuePersonalAccessToken(grants: $grants, comment: $comment) {\n    secret\n    token {\n      expires\n    }\n  }\n}"
    revoke_pat_query = "mutation RevokePAT($token_id: Int!) {\n  revokePersonalAccessToken(id: $token_id) {\n    id\n  }\n}"
    revoke_bearer_query = "mutation RevokeBearer($token_hash: String!) {\n  revokeOAuthGrant(hash: $token_hash) {\n    id\n  }\n}"
    register_client_query = "mutation RegisterClient($client_name: String!, $client_description: String, $client_url: String, $redirect_uri: String!) {\n  registration: registerOAuthClient(\n    redirectUri: $redirect_uri\n    clientName: $client_name\n    clientDescription: $client_description\n    clientUrl: $client_url\n  ) {\n    ...clientRegistration\n  }\n}"
    get_o_auth_client_query = "query GetOAuthClient($uuid: String!) {\n  client: oauthClientByUUID(uuid: $uuid) {\n    description\n    name\n    redirectUrl\n    url\n    uuid\n    owner {\n      __typename\n      canonicalName\n      ... on User {\n        username\n      }\n    }\n  }\n}"
    reregister_o_auth_client_query = "mutation ReregisterOAuthClient($uuid: String!, $client_name: String!, $client_description: String, $client_url: String, $redirect_uri: String!) {\n  revocation: revokeOAuthClient(uuid: $uuid) {\n    id\n  }\n  registration: registerOAuthClient(\n    redirectUri: $redirect_uri\n    clientName: $client_name\n    clientDescription: $client_description\n    clientUrl: $client_url\n  ) {\n    ...clientRegistration\n  }\n}"
    unregister_o_auth_client_query = "mutation UnregisterOAuthClient($uuid: String!) {\n  revokeOAuthClient(uuid: $uuid) {\n    id\n  }\n}"
    issue_auth_code_query = "mutation IssueAuthCode($client_uuid: String!, $grants: String!) {\n  code: issueAuthorizationCode(clientUUID: $client_uuid, grants: $grants)\n}"
    issue_bearer_token_query = "mutation IssueBearerToken($authorization: String!, $client_uuid: String!, $client_secret: String!, $redirect_uri: String) {\n  grant: issueOAuthGrant(\n    authorization: $authorization\n    clientUUID: $client_uuid\n    clientSecret: $client_secret\n    redirectUri: $redirect_uri\n  ) {\n    ...oauthGrant\n  }\n}"
    refresh_grant_query = "mutation RefreshGrant($refresh_token: String!, $client_uuid: String!, $client_secret: String!, $scope: String) {\n  grant: refreshOAuthGrant(\n    refreshToken: $refresh_token\n    clientUUID: $client_uuid\n    clientSecret: $client_secret\n    grants: $scope\n  ) {\n    ...oauthGrant\n  }\n}"
    get_introspection_query = "query GetIntrospection {\n  user: me {\n    username\n  }\n  grant: myOauthGrant {\n    client {\n      uuid\n    }\n    issued\n    expires\n    grants\n  }\n}"
    update_profile_query = "mutation UpdateProfile($input: UserInput!) {\n  updateUser(input: $input) {\n    id\n    email\n  }\n}"
    confirm_email_change_query = "mutation ConfirmEmailChange($token: String!) {\n  user: confirmEmailChange(token: $token) {\n    id\n  }\n}"
    delete_user_query = (
        "mutation DeleteUser($reserve: Boolean!) {\n  deleteUser(reserve: $reserve)\n}"
    )
    enable_totp_query = "mutation EnableTOTP($secret: String!) {\n  config: enableTOTP(secret: $secret) {\n    recoveryCodes\n  }\n}"
