# Generated by ariadne-codegen on 2023-07-20 15:44
# Source: operations.graphql

from .archive_customer import ArchiveCustomer
from .base_client import BaseClient
from .cancel_subscription import CancelSubscription
from .cancel_subscription_updates import CancelSubscriptionUpdates
from .create_subscription import CreateSubscription
from .estimate_subscription import EstimateSubscription
from .estimate_subscription_update import EstimateSubscriptionUpdate
from .get_active_subscriptions import GetActiveSubscriptions
from .get_coupons import GetCoupons
from .get_customer_by_id import GetCustomerById
from .get_customer_portal_by_ref_id import GetCustomerPortalByRefId
from .get_entitlement import GetEntitlement
from .get_entitlements import GetEntitlements
from .get_mock_paywall import GetMockPaywall
from .get_paywall import GetPaywall
from .get_products import GetProducts
from .get_sdk_configuration import GetSdkConfiguration
from .import_customer import ImportCustomer
from .import_customer_bulk import ImportCustomerBulk
from .import_subscriptions_bulk import ImportSubscriptionsBulk
from .input_types import (
    ArchiveCustomerInput,
    CustomerPortalInput,
    EntitlementCheckRequested,
    EstimateSubscriptionInput,
    EstimateSubscriptionUpdateInput,
    FetchEntitlementQuery,
    FetchEntitlementsQuery,
    GetActiveSubscriptionsInput,
    GetCustomerByRefIdInput,
    GetPaywallInput,
    ImportCustomerBulk,
    ImportCustomerInput,
    ImportSubscriptionsBulk,
    ProvisionCustomerInput,
    ProvisionSubscriptionInput,
    SubscriptionCancellationInput,
    SubscriptionInput,
    SubscriptionMigrationInput,
    SubscriptionUpdateScheduleCancellationInput,
    UpdateCustomerInput,
    UpdateSubscriptionInput,
    UsageEventsReportInput,
    UsageHistoryInput,
    UsageMeasurementCreateInput,
)
from .migrate_subscription_to_latest import MigrateSubscriptionToLatest
from .provision_customer import ProvisionCustomer
from .provision_subscription import ProvisionSubscription
from .report_entitlement_check_requested import ReportEntitlementCheckRequested
from .report_event import ReportEvent
from .report_usage import ReportUsage
from .update_customer import UpdateCustomer
from .update_subscription import UpdateSubscription
from .usage_history import UsageHistory


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


class Client(BaseClient):
    def provision_customer(self, input: ProvisionCustomerInput) -> ProvisionCustomer:
        query = gql(
            """
            mutation ProvisionCustomer($input: ProvisionCustomerInput!) {
              provisionCustomer(input: $input) {
                customer {
                  ...SlimCustomerFragment
                }
                subscriptionDecisionStrategy
                subscription {
                  ...SlimSubscriptionFragment
                }
              }
            }

            fragment CustomerResourceFragment on CustomerResource {
              resourceId
            }

            fragment PriceFragment on Price {
              billingModel
              billingPeriod
              billingId
              minUnitQuantity
              maxUnitQuantity
              billingCountryCode
              price {
                amount
                currency
              }
              feature {
                refId
                featureUnits
                featureUnitsPlural
                displayName
                description
              }
            }

            fragment SlimCustomerFragment on Customer {
              id
              name
              email
              createdAt
              updatedAt
              refId
              billingId
              additionalMetaData
            }

            fragment SlimSubscriptionFragment on CustomerSubscription {
              id
              refId
              status
              additionalMetaData
              billingId
              billingLinkUrl
              effectiveEndDate
              currentBillingPeriodEnd
              pricingType
              resource {
                ...CustomerResourceFragment
              }
              experimentInfo {
                name
                id
                groupName
                groupType
              }
              prices {
                usageLimit
                price {
                  ...PriceFragment
                }
              }
              totalPrice {
                ...TotalPriceFragment
              }
              plan {
                id
                refId
              }
              addons {
                quantity
                addon {
                  id
                  refId
                }
              }
              customer {
                id
                refId
              }
            }

            fragment TotalPriceFragment on CustomerSubscriptionTotalPrice {
              subTotal {
                amount
                currency
              }
              total {
                amount
                currency
              }
            }
            """
        )
        variables: dict[str, object] = {"input": input}
        response = self.execute(query=query, variables=variables)
        data = self.get_data(response)
        return ProvisionCustomer.parse_obj(data)

    def import_customer_bulk(self, input: ImportCustomerBulk) -> ImportCustomerBulk:
        query = gql(
            """
            mutation ImportCustomerBulk($input: ImportCustomerBulk!) {
              importCustomersBulk(input: $input)
            }
            """
        )
        variables: dict[str, object] = {"input": input}
        response = self.execute(query=query, variables=variables)
        data = self.get_data(response)
        return ImportCustomerBulk.parse_obj(data)

    def import_customer(self, input: ImportCustomerInput) -> ImportCustomer:
        query = gql(
            """
            mutation ImportCustomer($input: ImportCustomerInput!) {
              importCustomer: importOneCustomer(input: $input) {
                ...SlimCustomerFragment
              }
            }

            fragment SlimCustomerFragment on Customer {
              id
              name
              email
              createdAt
              updatedAt
              refId
              billingId
              additionalMetaData
            }
            """
        )
        variables: dict[str, object] = {"input": input}
        response = self.execute(query=query, variables=variables)
        data = self.get_data(response)
        return ImportCustomer.parse_obj(data)

    def update_customer(self, input: UpdateCustomerInput) -> UpdateCustomer:
        query = gql(
            """
            mutation UpdateCustomer($input: UpdateCustomerInput!) {
              updateCustomer: updateOneCustomer(input: $input) {
                ...SlimCustomerFragment
              }
            }

            fragment SlimCustomerFragment on Customer {
              id
              name
              email
              createdAt
              updatedAt
              refId
              billingId
              additionalMetaData
            }
            """
        )
        variables: dict[str, object] = {"input": input}
        response = self.execute(query=query, variables=variables)
        data = self.get_data(response)
        return UpdateCustomer.parse_obj(data)

    def provision_subscription(
        self, input: ProvisionSubscriptionInput
    ) -> ProvisionSubscription:
        query = gql(
            """
            mutation ProvisionSubscription($input: ProvisionSubscriptionInput!) {
              provisionSubscription: provisionSubscriptionV2(input: $input) {
                checkoutUrl
                status
                subscription {
                  ...SlimSubscriptionFragment
                }
              }
            }

            fragment CustomerResourceFragment on CustomerResource {
              resourceId
            }

            fragment PriceFragment on Price {
              billingModel
              billingPeriod
              billingId
              minUnitQuantity
              maxUnitQuantity
              billingCountryCode
              price {
                amount
                currency
              }
              feature {
                refId
                featureUnits
                featureUnitsPlural
                displayName
                description
              }
            }

            fragment SlimSubscriptionFragment on CustomerSubscription {
              id
              refId
              status
              additionalMetaData
              billingId
              billingLinkUrl
              effectiveEndDate
              currentBillingPeriodEnd
              pricingType
              resource {
                ...CustomerResourceFragment
              }
              experimentInfo {
                name
                id
                groupName
                groupType
              }
              prices {
                usageLimit
                price {
                  ...PriceFragment
                }
              }
              totalPrice {
                ...TotalPriceFragment
              }
              plan {
                id
                refId
              }
              addons {
                quantity
                addon {
                  id
                  refId
                }
              }
              customer {
                id
                refId
              }
            }

            fragment TotalPriceFragment on CustomerSubscriptionTotalPrice {
              subTotal {
                amount
                currency
              }
              total {
                amount
                currency
              }
            }
            """
        )
        variables: dict[str, object] = {"input": input}
        response = self.execute(query=query, variables=variables)
        data = self.get_data(response)
        return ProvisionSubscription.parse_obj(data)

    def import_subscriptions_bulk(
        self, input: ImportSubscriptionsBulk
    ) -> ImportSubscriptionsBulk:
        query = gql(
            """
            mutation ImportSubscriptionsBulk($input: ImportSubscriptionsBulk!) {
              importSubscriptionsBulk(input: $input)
            }
            """
        )
        variables: dict[str, object] = {"input": input}
        response = self.execute(query=query, variables=variables)
        data = self.get_data(response)
        return ImportSubscriptionsBulk.parse_obj(data)

    def update_subscription(self, input: UpdateSubscriptionInput) -> UpdateSubscription:
        query = gql(
            """
            mutation UpdateSubscription($input: UpdateSubscriptionInput!) {
              updateSubscription: updateOneSubscription(input: $input) {
                ...SlimSubscriptionFragment
              }
            }

            fragment CustomerResourceFragment on CustomerResource {
              resourceId
            }

            fragment PriceFragment on Price {
              billingModel
              billingPeriod
              billingId
              minUnitQuantity
              maxUnitQuantity
              billingCountryCode
              price {
                amount
                currency
              }
              feature {
                refId
                featureUnits
                featureUnitsPlural
                displayName
                description
              }
            }

            fragment SlimSubscriptionFragment on CustomerSubscription {
              id
              refId
              status
              additionalMetaData
              billingId
              billingLinkUrl
              effectiveEndDate
              currentBillingPeriodEnd
              pricingType
              resource {
                ...CustomerResourceFragment
              }
              experimentInfo {
                name
                id
                groupName
                groupType
              }
              prices {
                usageLimit
                price {
                  ...PriceFragment
                }
              }
              totalPrice {
                ...TotalPriceFragment
              }
              plan {
                id
                refId
              }
              addons {
                quantity
                addon {
                  id
                  refId
                }
              }
              customer {
                id
                refId
              }
            }

            fragment TotalPriceFragment on CustomerSubscriptionTotalPrice {
              subTotal {
                amount
                currency
              }
              total {
                amount
                currency
              }
            }
            """
        )
        variables: dict[str, object] = {"input": input}
        response = self.execute(query=query, variables=variables)
        data = self.get_data(response)
        return UpdateSubscription.parse_obj(data)

    def cancel_subscription(
        self, input: SubscriptionCancellationInput
    ) -> CancelSubscription:
        query = gql(
            """
            mutation CancelSubscription($input: SubscriptionCancellationInput!) {
              cancelSubscription(input: $input) {
                ...SlimSubscriptionFragment
              }
            }

            fragment CustomerResourceFragment on CustomerResource {
              resourceId
            }

            fragment PriceFragment on Price {
              billingModel
              billingPeriod
              billingId
              minUnitQuantity
              maxUnitQuantity
              billingCountryCode
              price {
                amount
                currency
              }
              feature {
                refId
                featureUnits
                featureUnitsPlural
                displayName
                description
              }
            }

            fragment SlimSubscriptionFragment on CustomerSubscription {
              id
              refId
              status
              additionalMetaData
              billingId
              billingLinkUrl
              effectiveEndDate
              currentBillingPeriodEnd
              pricingType
              resource {
                ...CustomerResourceFragment
              }
              experimentInfo {
                name
                id
                groupName
                groupType
              }
              prices {
                usageLimit
                price {
                  ...PriceFragment
                }
              }
              totalPrice {
                ...TotalPriceFragment
              }
              plan {
                id
                refId
              }
              addons {
                quantity
                addon {
                  id
                  refId
                }
              }
              customer {
                id
                refId
              }
            }

            fragment TotalPriceFragment on CustomerSubscriptionTotalPrice {
              subTotal {
                amount
                currency
              }
              total {
                amount
                currency
              }
            }
            """
        )
        variables: dict[str, object] = {"input": input}
        response = self.execute(query=query, variables=variables)
        data = self.get_data(response)
        return CancelSubscription.parse_obj(data)

    def estimate_subscription(
        self, input: EstimateSubscriptionInput
    ) -> EstimateSubscription:
        query = gql(
            """
            mutation EstimateSubscription($input: EstimateSubscriptionInput!) {
              estimateSubscription(input: $input) {
                ...SubscriptionPreviewFragment
              }
            }

            fragment SubscriptionPreviewFragment on SubscriptionPreview {
              subTotal {
                amount
                currency
              }
              totalExcludingTax {
                amount
                currency
              }
              total {
                amount
                currency
              }
              taxDetails {
                displayName
                percentage
                inclusive
              }
              tax {
                amount
                currency
              }
              billingPeriodRange {
                start
                end
              }
              discount {
                type
                value
                durationType
                durationInMonths
              }
              subscription {
                subTotal {
                  amount
                  currency
                }
                totalExcludingTax {
                  amount
                  currency
                }
                total {
                  amount
                  currency
                }
                tax {
                  amount
                  currency
                }
              }
              proration {
                prorationDate
                credit {
                  amount
                  currency
                }
                debit {
                  amount
                  currency
                }
                netAmount {
                  amount
                  currency
                }
              }
            }
            """
        )
        variables: dict[str, object] = {"input": input}
        response = self.execute(query=query, variables=variables)
        data = self.get_data(response)
        return EstimateSubscription.parse_obj(data)

    def estimate_subscription_update(
        self, input: EstimateSubscriptionUpdateInput
    ) -> EstimateSubscriptionUpdate:
        query = gql(
            """
            mutation EstimateSubscriptionUpdate($input: EstimateSubscriptionUpdateInput!) {
              estimateSubscriptionUpdate(input: $input) {
                ...SubscriptionPreviewFragment
              }
            }

            fragment SubscriptionPreviewFragment on SubscriptionPreview {
              subTotal {
                amount
                currency
              }
              totalExcludingTax {
                amount
                currency
              }
              total {
                amount
                currency
              }
              taxDetails {
                displayName
                percentage
                inclusive
              }
              tax {
                amount
                currency
              }
              billingPeriodRange {
                start
                end
              }
              discount {
                type
                value
                durationType
                durationInMonths
              }
              subscription {
                subTotal {
                  amount
                  currency
                }
                totalExcludingTax {
                  amount
                  currency
                }
                total {
                  amount
                  currency
                }
                tax {
                  amount
                  currency
                }
              }
              proration {
                prorationDate
                credit {
                  amount
                  currency
                }
                debit {
                  amount
                  currency
                }
                netAmount {
                  amount
                  currency
                }
              }
            }
            """
        )
        variables: dict[str, object] = {"input": input}
        response = self.execute(query=query, variables=variables)
        data = self.get_data(response)
        return EstimateSubscriptionUpdate.parse_obj(data)

    def cancel_subscription_updates(
        self, input: SubscriptionUpdateScheduleCancellationInput
    ) -> CancelSubscriptionUpdates:
        query = gql(
            """
            mutation CancelSubscriptionUpdates($input: SubscriptionUpdateScheduleCancellationInput!) {
              cancelSchedule(input: $input)
            }
            """
        )
        variables: dict[str, object] = {"input": input}
        response = self.execute(query=query, variables=variables)
        data = self.get_data(response)
        return CancelSubscriptionUpdates.parse_obj(data)

    def report_usage(self, input: UsageMeasurementCreateInput) -> ReportUsage:
        query = gql(
            """
            mutation ReportUsage($input: UsageMeasurementCreateInput!) {
              createUsageMeasurement(usageMeasurement: $input) {
                id
                currentUsage
                nextResetDate
                timestamp
              }
            }
            """
        )
        variables: dict[str, object] = {"input": input}
        response = self.execute(query=query, variables=variables)
        data = self.get_data(response)
        return ReportUsage.parse_obj(data)

    def report_event(self, input: UsageEventsReportInput) -> ReportEvent:
        query = gql(
            """
            mutation ReportEvent($input: UsageEventsReportInput!) {
              reportEvent(events: $input)
            }
            """
        )
        variables: dict[str, object] = {"input": input}
        response = self.execute(query=query, variables=variables)
        data = self.get_data(response)
        return ReportEvent.parse_obj(data)

    def report_entitlement_check_requested(
        self, entitlement_check_requested: EntitlementCheckRequested
    ) -> ReportEntitlementCheckRequested:
        query = gql(
            """
            mutation ReportEntitlementCheckRequested($entitlementCheckRequested: EntitlementCheckRequested!) {
              reportEntitlementCheckRequested(
                entitlementCheckRequested: $entitlementCheckRequested
              )
            }
            """
        )
        variables: dict[str, object] = {
            "entitlementCheckRequested": entitlement_check_requested
        }
        response = self.execute(query=query, variables=variables)
        data = self.get_data(response)
        return ReportEntitlementCheckRequested.parse_obj(data)

    def create_subscription(self, input: SubscriptionInput) -> CreateSubscription:
        query = gql(
            """
            mutation CreateSubscription($input: SubscriptionInput!) {
              createSubscription(subscription: $input) {
                ...SlimSubscriptionFragment
              }
            }

            fragment CustomerResourceFragment on CustomerResource {
              resourceId
            }

            fragment PriceFragment on Price {
              billingModel
              billingPeriod
              billingId
              minUnitQuantity
              maxUnitQuantity
              billingCountryCode
              price {
                amount
                currency
              }
              feature {
                refId
                featureUnits
                featureUnitsPlural
                displayName
                description
              }
            }

            fragment SlimSubscriptionFragment on CustomerSubscription {
              id
              refId
              status
              additionalMetaData
              billingId
              billingLinkUrl
              effectiveEndDate
              currentBillingPeriodEnd
              pricingType
              resource {
                ...CustomerResourceFragment
              }
              experimentInfo {
                name
                id
                groupName
                groupType
              }
              prices {
                usageLimit
                price {
                  ...PriceFragment
                }
              }
              totalPrice {
                ...TotalPriceFragment
              }
              plan {
                id
                refId
              }
              addons {
                quantity
                addon {
                  id
                  refId
                }
              }
              customer {
                id
                refId
              }
            }

            fragment TotalPriceFragment on CustomerSubscriptionTotalPrice {
              subTotal {
                amount
                currency
              }
              total {
                amount
                currency
              }
            }
            """
        )
        variables: dict[str, object] = {"input": input}
        response = self.execute(query=query, variables=variables)
        data = self.get_data(response)
        return CreateSubscription.parse_obj(data)

    def migrate_subscription_to_latest(
        self, input: SubscriptionMigrationInput
    ) -> MigrateSubscriptionToLatest:
        query = gql(
            """
            mutation MigrateSubscriptionToLatest($input: SubscriptionMigrationInput!) {
              migrateSubscriptionToLatest(input: $input) {
                subscriptionId
              }
            }
            """
        )
        variables: dict[str, object] = {"input": input}
        response = self.execute(query=query, variables=variables)
        data = self.get_data(response)
        return MigrateSubscriptionToLatest.parse_obj(data)

    def archive_customer(self, input: ArchiveCustomerInput) -> ArchiveCustomer:
        query = gql(
            """
            mutation ArchiveCustomer($input: ArchiveCustomerInput!) {
              archiveCustomer(input: $input) {
                customerId
              }
            }
            """
        )
        variables: dict[str, object] = {"input": input}
        response = self.execute(query=query, variables=variables)
        data = self.get_data(response)
        return ArchiveCustomer.parse_obj(data)

    def get_customer_by_id(self, input: GetCustomerByRefIdInput) -> GetCustomerById:
        query = gql(
            """
            query GetCustomerById($input: GetCustomerByRefIdInput!) {
              getCustomerByRefId(input: $input) {
                ...CustomerWithSubscriptionsFragment
              }
            }

            fragment AddonFragment on Addon {
              id
              refId
              billingId
              displayName
              description
              additionalMetaData
              entitlements {
                ...PackageEntitlementFragment
              }
              prices {
                ...PriceFragment
              }
              pricingType
            }

            fragment CouponFragment on Coupon {
              id
              discountValue
              type
              additionalMetaData
              refId
              name
              description
              createdAt
              updatedAt
              billingId
              billingLinkUrl
              type
              status
              syncStates {
                vendorIdentifier
                status
              }
              customers {
                id
              }
            }

            fragment CustomerFragment on Customer {
              ...SlimCustomerFragment
              hasPaymentMethod
              hasActiveSubscription
              defaultPaymentExpirationMonth
              defaultPaymentExpirationYear
              defaultPaymentMethodLast4Digits
              trialedPlans {
                productId
                productRefId
                planRefId
                planId
              }
              experimentInfo {
                groupType
                groupName
                id
                name
              }
              coupon {
                ...CouponFragment
              }
              eligibleForTrial {
                productId
                productRefId
                eligible
              }
              promotionalEntitlements {
                ...PromotionalEntitlementFragment
              }
            }

            fragment CustomerResourceFragment on CustomerResource {
              resourceId
            }

            fragment CustomerWithSubscriptionsFragment on Customer {
              ...CustomerFragment
              subscriptions {
                ...SubscriptionFragment
              }
            }

            fragment PackageEntitlementFragment on PackageEntitlement {
              usageLimit
              hasUnlimitedUsage
              featureId
              resetPeriod
              hiddenFromWidgets
              isCustom
              displayNameOverride
              feature {
                featureType
                meterType
                featureUnits
                featureUnitsPlural
                displayName
                description
                refId
                additionalMetaData
              }
            }

            fragment PlanFragment on Plan {
              id
              refId
              displayName
              description
              billingId
              additionalMetaData
              product {
                ...ProductFragment
              }
              basePlan {
                refId
                displayName
              }
              entitlements {
                ...PackageEntitlementFragment
              }
              inheritedEntitlements {
                ...PackageEntitlementFragment
              }
              compatibleAddons {
                ...AddonFragment
              }
              prices {
                ...PriceFragment
              }
              pricingType
              defaultTrialConfig {
                duration
                units
              }
            }

            fragment PriceFragment on Price {
              billingModel
              billingPeriod
              billingId
              minUnitQuantity
              maxUnitQuantity
              billingCountryCode
              price {
                amount
                currency
              }
              feature {
                refId
                featureUnits
                featureUnitsPlural
                displayName
                description
              }
            }

            fragment ProductFragment on Product {
              refId
              displayName
              description
              additionalMetaData
              productSettings {
                downgradePlan {
                  refId
                  displayName
                }
              }
            }

            fragment PromotionalEntitlementFragment on PromotionalEntitlement {
              status
              usageLimit
              featureId
              hasUnlimitedUsage
              resetPeriod
              endDate
              isVisible
              feature {
                featureType
                meterType
                featureUnits
                featureUnitsPlural
                displayName
                description
                refId
                additionalMetaData
              }
            }

            fragment SlimCustomerFragment on Customer {
              id
              name
              email
              createdAt
              updatedAt
              refId
              billingId
              additionalMetaData
            }

            fragment SubscriptionFragment on CustomerSubscription {
              id
              startDate
              endDate
              trialEndDate
              cancellationDate
              effectiveEndDate
              status
              refId
              currentBillingPeriodEnd
              additionalMetaData
              billingId
              billingLinkUrl
              resource {
                ...CustomerResourceFragment
              }
              experimentInfo {
                name
                groupType
                groupName
                id
              }
              prices {
                usageLimit
                price {
                  ...PriceFragment
                }
              }
              totalPrice {
                ...TotalPriceFragment
              }
              pricingType
              plan {
                ...PlanFragment
              }
              addons {
                id
                quantity
                addon {
                  ...AddonFragment
                }
              }
              scheduledUpdates {
                ...SubscriptionScheduledUpdateData
              }
            }

            fragment SubscriptionScheduledUpdateData on SubscriptionScheduledUpdate {
              subscriptionScheduleType
              scheduleStatus
              scheduledExecutionTime
              targetPackage {
                id
                refId
                displayName
              }
              scheduleVariables {
                ... on DowngradeChangeVariables {
                  addonRefIds
                  billingPeriod
                  downgradePlanRefId
                }
                ... on BillingPeriodChangeVariables {
                  billingPeriod
                }
                ... on UnitAmountChangeVariables {
                  newUnitAmount
                  featureId
                }
              }
            }

            fragment TotalPriceFragment on CustomerSubscriptionTotalPrice {
              subTotal {
                amount
                currency
              }
              total {
                amount
                currency
              }
            }
            """
        )
        variables: dict[str, object] = {"input": input}
        response = self.execute(query=query, variables=variables)
        data = self.get_data(response)
        return GetCustomerById.parse_obj(data)

    def get_active_subscriptions(
        self, input: GetActiveSubscriptionsInput
    ) -> GetActiveSubscriptions:
        query = gql(
            """
            query GetActiveSubscriptions($input: GetActiveSubscriptionsInput!) {
              getActiveSubscriptions(input: $input) {
                ...SubscriptionFragment
              }
            }

            fragment AddonFragment on Addon {
              id
              refId
              billingId
              displayName
              description
              additionalMetaData
              entitlements {
                ...PackageEntitlementFragment
              }
              prices {
                ...PriceFragment
              }
              pricingType
            }

            fragment CustomerResourceFragment on CustomerResource {
              resourceId
            }

            fragment PackageEntitlementFragment on PackageEntitlement {
              usageLimit
              hasUnlimitedUsage
              featureId
              resetPeriod
              hiddenFromWidgets
              isCustom
              displayNameOverride
              feature {
                featureType
                meterType
                featureUnits
                featureUnitsPlural
                displayName
                description
                refId
                additionalMetaData
              }
            }

            fragment PlanFragment on Plan {
              id
              refId
              displayName
              description
              billingId
              additionalMetaData
              product {
                ...ProductFragment
              }
              basePlan {
                refId
                displayName
              }
              entitlements {
                ...PackageEntitlementFragment
              }
              inheritedEntitlements {
                ...PackageEntitlementFragment
              }
              compatibleAddons {
                ...AddonFragment
              }
              prices {
                ...PriceFragment
              }
              pricingType
              defaultTrialConfig {
                duration
                units
              }
            }

            fragment PriceFragment on Price {
              billingModel
              billingPeriod
              billingId
              minUnitQuantity
              maxUnitQuantity
              billingCountryCode
              price {
                amount
                currency
              }
              feature {
                refId
                featureUnits
                featureUnitsPlural
                displayName
                description
              }
            }

            fragment ProductFragment on Product {
              refId
              displayName
              description
              additionalMetaData
              productSettings {
                downgradePlan {
                  refId
                  displayName
                }
              }
            }

            fragment SubscriptionFragment on CustomerSubscription {
              id
              startDate
              endDate
              trialEndDate
              cancellationDate
              effectiveEndDate
              status
              refId
              currentBillingPeriodEnd
              additionalMetaData
              billingId
              billingLinkUrl
              resource {
                ...CustomerResourceFragment
              }
              experimentInfo {
                name
                groupType
                groupName
                id
              }
              prices {
                usageLimit
                price {
                  ...PriceFragment
                }
              }
              totalPrice {
                ...TotalPriceFragment
              }
              pricingType
              plan {
                ...PlanFragment
              }
              addons {
                id
                quantity
                addon {
                  ...AddonFragment
                }
              }
              scheduledUpdates {
                ...SubscriptionScheduledUpdateData
              }
            }

            fragment SubscriptionScheduledUpdateData on SubscriptionScheduledUpdate {
              subscriptionScheduleType
              scheduleStatus
              scheduledExecutionTime
              targetPackage {
                id
                refId
                displayName
              }
              scheduleVariables {
                ... on DowngradeChangeVariables {
                  addonRefIds
                  billingPeriod
                  downgradePlanRefId
                }
                ... on BillingPeriodChangeVariables {
                  billingPeriod
                }
                ... on UnitAmountChangeVariables {
                  newUnitAmount
                  featureId
                }
              }
            }

            fragment TotalPriceFragment on CustomerSubscriptionTotalPrice {
              subTotal {
                amount
                currency
              }
              total {
                amount
                currency
              }
            }
            """
        )
        variables: dict[str, object] = {"input": input}
        response = self.execute(query=query, variables=variables)
        data = self.get_data(response)
        return GetActiveSubscriptions.parse_obj(data)

    def get_coupons(self) -> GetCoupons:
        query = gql(
            """
            query GetCoupons {
              coupons(filter: {status: {eq: ACTIVE}}, paging: {first: 50}) {
                edges {
                  node {
                    ...CouponFragment
                  }
                }
              }
            }

            fragment CouponFragment on Coupon {
              id
              discountValue
              type
              additionalMetaData
              refId
              name
              description
              createdAt
              updatedAt
              billingId
              billingLinkUrl
              type
              status
              syncStates {
                vendorIdentifier
                status
              }
              customers {
                id
              }
            }
            """
        )
        variables: dict[str, object] = {}
        response = self.execute(query=query, variables=variables)
        data = self.get_data(response)
        return GetCoupons.parse_obj(data)

    def get_paywall(self, input: GetPaywallInput) -> GetPaywall:
        query = gql(
            """
            query GetPaywall($input: GetPaywallInput!) {
              paywall(input: $input) {
                ...PaywallFragment
              }
            }

            fragment AddonFragment on Addon {
              id
              refId
              billingId
              displayName
              description
              additionalMetaData
              entitlements {
                ...PackageEntitlementFragment
              }
              prices {
                ...PriceFragment
              }
              pricingType
            }

            fragment CouponFragment on Coupon {
              id
              discountValue
              type
              additionalMetaData
              refId
              name
              description
              createdAt
              updatedAt
              billingId
              billingLinkUrl
              type
              status
              syncStates {
                vendorIdentifier
                status
              }
              customers {
                id
              }
            }

            fragment CustomerFragment on Customer {
              ...SlimCustomerFragment
              hasPaymentMethod
              hasActiveSubscription
              defaultPaymentExpirationMonth
              defaultPaymentExpirationYear
              defaultPaymentMethodLast4Digits
              trialedPlans {
                productId
                productRefId
                planRefId
                planId
              }
              experimentInfo {
                groupType
                groupName
                id
                name
              }
              coupon {
                ...CouponFragment
              }
              eligibleForTrial {
                productId
                productRefId
                eligible
              }
              promotionalEntitlements {
                ...PromotionalEntitlementFragment
              }
            }

            fragment CustomerResourceFragment on CustomerResource {
              resourceId
            }

            fragment FontVariantFragment on FontVariant {
              fontSize
              fontWeight
            }

            fragment LayoutConfigurationFragment on PaywallLayoutConfiguration {
              alignment
              planWidth
              planMargin
              planPadding
            }

            fragment PackageEntitlementFragment on PackageEntitlement {
              usageLimit
              hasUnlimitedUsage
              featureId
              resetPeriod
              hiddenFromWidgets
              isCustom
              displayNameOverride
              feature {
                featureType
                meterType
                featureUnits
                featureUnitsPlural
                displayName
                description
                refId
                additionalMetaData
              }
            }

            fragment PaywallCalculatedPricePointsFragment on PaywallPricePoint {
              planId
              additionalChargesMayApply
              billingPeriod
              amount
              currency
              billingCountryCode
              feature {
                refId
                featureUnits
                featureUnitsPlural
                displayName
                description
              }
            }

            fragment PaywallConfigurationFragment on PaywallConfiguration {
              palette {
                primary
                textColor
                backgroundColor
                borderColor
                currentPlanBackground
              }
              typography {
                ...TypographyConfigurationFragment
              }
              layout {
                ...LayoutConfigurationFragment
              }
              customCss
            }

            fragment PaywallCurrency on PaywallCurrency {
              code
              symbol
            }

            fragment PaywallFragment on Paywall {
              plans {
                ...PlanFragment
              }
              currency {
                ...PaywallCurrency
              }
              configuration {
                ...PaywallConfigurationFragment
              }
              customer {
                ...CustomerFragment
              }
              activeSubscriptions {
                ...SubscriptionFragment
              }
              resource {
                ...CustomerResourceFragment
              }
              paywallCalculatedPricePoints {
                ...PaywallCalculatedPricePointsFragment
              }
            }

            fragment PlanFragment on Plan {
              id
              refId
              displayName
              description
              billingId
              additionalMetaData
              product {
                ...ProductFragment
              }
              basePlan {
                refId
                displayName
              }
              entitlements {
                ...PackageEntitlementFragment
              }
              inheritedEntitlements {
                ...PackageEntitlementFragment
              }
              compatibleAddons {
                ...AddonFragment
              }
              prices {
                ...PriceFragment
              }
              pricingType
              defaultTrialConfig {
                duration
                units
              }
            }

            fragment PriceFragment on Price {
              billingModel
              billingPeriod
              billingId
              minUnitQuantity
              maxUnitQuantity
              billingCountryCode
              price {
                amount
                currency
              }
              feature {
                refId
                featureUnits
                featureUnitsPlural
                displayName
                description
              }
            }

            fragment ProductFragment on Product {
              refId
              displayName
              description
              additionalMetaData
              productSettings {
                downgradePlan {
                  refId
                  displayName
                }
              }
            }

            fragment PromotionalEntitlementFragment on PromotionalEntitlement {
              status
              usageLimit
              featureId
              hasUnlimitedUsage
              resetPeriod
              endDate
              isVisible
              feature {
                featureType
                meterType
                featureUnits
                featureUnitsPlural
                displayName
                description
                refId
                additionalMetaData
              }
            }

            fragment SlimCustomerFragment on Customer {
              id
              name
              email
              createdAt
              updatedAt
              refId
              billingId
              additionalMetaData
            }

            fragment SubscriptionFragment on CustomerSubscription {
              id
              startDate
              endDate
              trialEndDate
              cancellationDate
              effectiveEndDate
              status
              refId
              currentBillingPeriodEnd
              additionalMetaData
              billingId
              billingLinkUrl
              resource {
                ...CustomerResourceFragment
              }
              experimentInfo {
                name
                groupType
                groupName
                id
              }
              prices {
                usageLimit
                price {
                  ...PriceFragment
                }
              }
              totalPrice {
                ...TotalPriceFragment
              }
              pricingType
              plan {
                ...PlanFragment
              }
              addons {
                id
                quantity
                addon {
                  ...AddonFragment
                }
              }
              scheduledUpdates {
                ...SubscriptionScheduledUpdateData
              }
            }

            fragment SubscriptionScheduledUpdateData on SubscriptionScheduledUpdate {
              subscriptionScheduleType
              scheduleStatus
              scheduledExecutionTime
              targetPackage {
                id
                refId
                displayName
              }
              scheduleVariables {
                ... on DowngradeChangeVariables {
                  addonRefIds
                  billingPeriod
                  downgradePlanRefId
                }
                ... on BillingPeriodChangeVariables {
                  billingPeriod
                }
                ... on UnitAmountChangeVariables {
                  newUnitAmount
                  featureId
                }
              }
            }

            fragment TotalPriceFragment on CustomerSubscriptionTotalPrice {
              subTotal {
                amount
                currency
              }
              total {
                amount
                currency
              }
            }

            fragment TypographyConfigurationFragment on TypographyConfiguration {
              fontFamily
              h1 {
                ...FontVariantFragment
              }
              h2 {
                ...FontVariantFragment
              }
              h3 {
                ...FontVariantFragment
              }
              body {
                ...FontVariantFragment
              }
            }
            """
        )
        variables: dict[str, object] = {"input": input}
        response = self.execute(query=query, variables=variables)
        data = self.get_data(response)
        return GetPaywall.parse_obj(data)

    def get_entitlements(self, query: FetchEntitlementsQuery) -> GetEntitlements:
        query = gql(
            """
            query GetEntitlements($query: FetchEntitlementsQuery!) {
              entitlements: cachedEntitlements(query: $query) {
                ...EntitlementFragment
              }
            }

            fragment EntitlementFragment on Entitlement {
              isGranted
              accessDeniedReason
              customerId
              resourceId
              usageLimit
              hasUnlimitedUsage
              currentUsage
              requestedUsage
              entitlementUpdatedAt
              usageUpdatedAt
              nextResetDate
              resetPeriod
              resetPeriodConfiguration {
                ...ResetPeriodConfigurationFragment
              }
              feature {
                ...FeatureFragment
              }
            }

            fragment FeatureFragment on EntitlementFeature {
              featureType
              meterType
              featureUnits
              featureUnitsPlural
              description
              displayName
              refId
            }

            fragment ResetPeriodConfigurationFragment on ResetPeriodConfiguration {
              __typename
              ... on MonthlyResetPeriodConfig {
                monthlyAccordingTo
              }
              ... on WeeklyResetPeriodConfig {
                weeklyAccordingTo
              }
            }
            """
        )
        variables: dict[str, object] = {"query": query}
        response = self.execute(query=query, variables=variables)
        data = self.get_data(response)
        return GetEntitlements.parse_obj(data)

    def get_entitlement(self, query: FetchEntitlementQuery) -> GetEntitlement:
        query = gql(
            """
            query GetEntitlement($query: FetchEntitlementQuery!) {
              entitlement(query: $query) {
                ...EntitlementFragment
              }
            }

            fragment EntitlementFragment on Entitlement {
              isGranted
              accessDeniedReason
              customerId
              resourceId
              usageLimit
              hasUnlimitedUsage
              currentUsage
              requestedUsage
              entitlementUpdatedAt
              usageUpdatedAt
              nextResetDate
              resetPeriod
              resetPeriodConfiguration {
                ...ResetPeriodConfigurationFragment
              }
              feature {
                ...FeatureFragment
              }
            }

            fragment FeatureFragment on EntitlementFeature {
              featureType
              meterType
              featureUnits
              featureUnitsPlural
              description
              displayName
              refId
            }

            fragment ResetPeriodConfigurationFragment on ResetPeriodConfiguration {
              __typename
              ... on MonthlyResetPeriodConfig {
                monthlyAccordingTo
              }
              ... on WeeklyResetPeriodConfig {
                weeklyAccordingTo
              }
            }
            """
        )
        variables: dict[str, object] = {"query": query}
        response = self.execute(query=query, variables=variables)
        data = self.get_data(response)
        return GetEntitlement.parse_obj(data)

    def get_products(self) -> GetProducts:
        query = gql(
            """
            query GetProducts {
              products(paging: {first: 50}) {
                edges {
                  node {
                    ...ProductFragment
                  }
                }
              }
            }

            fragment ProductFragment on Product {
              refId
              displayName
              description
              additionalMetaData
              productSettings {
                downgradePlan {
                  refId
                  displayName
                }
              }
            }
            """
        )
        variables: dict[str, object] = {}
        response = self.execute(query=query, variables=variables)
        data = self.get_data(response)
        return GetProducts.parse_obj(data)

    def get_sdk_configuration(self) -> GetSdkConfiguration:
        query = gql(
            """
            query GetSdkConfiguration {
              sdkConfiguration {
                sentryDsn
                isWidgetWatermarkEnabled
              }
            }
            """
        )
        variables: dict[str, object] = {}
        response = self.execute(query=query, variables=variables)
        data = self.get_data(response)
        return GetSdkConfiguration.parse_obj(data)

    def get_customer_portal_by_ref_id(
        self, input: CustomerPortalInput
    ) -> GetCustomerPortalByRefId:
        query = gql(
            """
            query GetCustomerPortalByRefId($input: CustomerPortalInput!) {
              customerPortal(input: $input) {
                ...CustomerPortalFragment
              }
            }

            fragment CustomerPortalBillingInformation on CustomerPortalBillingInformation {
              email
              name
              defaultPaymentMethodLast4Digits
              defaultPaymentMethodId
              defaultPaymentMethodLast4Digits
              defaultPaymentExpirationMonth
              defaultPaymentExpirationYear
            }

            fragment CustomerPortalConfigurationFragment on CustomerPortalConfiguration {
              palette {
                primary
                textColor
                backgroundColor
                borderColor
                currentPlanBackground
                iconsColor
                paywallBackgroundColor
              }
              typography {
                ...TypographyConfigurationFragment
              }
              customCss
            }

            fragment CustomerPortalEntitlement on Entitlement {
              isGranted
              usageLimit
              currentUsage
              hasUnlimitedUsage
              nextResetDate
              resetPeriod
              resetPeriodConfiguration {
                ...ResetPeriodConfigurationFragment
              }
              feature {
                ...FeatureFragment
              }
            }

            fragment CustomerPortalFragment on CustomerPortal {
              subscriptions {
                ...CustomerPortalSubscriptionFragment
              }
              entitlements {
                ...CustomerPortalEntitlement
              }
              promotionalEntitlements {
                ...CustomerPortalPromotionalEntitlement
              }
              billingInformation {
                ...CustomerPortalBillingInformation
              }
              showWatermark
              billingPortalUrl
              canUpgradeSubscription
              configuration {
                ...CustomerPortalConfigurationFragment
              }
              resource {
                ...CustomerResourceFragment
              }
            }

            fragment CustomerPortalPromotionalEntitlement on CustomerPortalPromotionalEntitlement {
              displayName
              hasUnlimitedUsage
              usageLimit
              period
              startDate
              endDate
            }

            fragment CustomerPortalSubscriptionAddon on CustomerPortalAddon {
              addonId
              description
              displayName
              quantity
            }

            fragment CustomerPortalSubscriptionFragment on CustomerPortalSubscription {
              subscriptionId
              planName
              pricingType
              prices {
                ...CustomerPortalSubscriptionPriceFragment
              }
              pricing {
                unitQuantity
                billingPeriod
                billingModel
                pricingType
                usageBasedEstimatedBill
                price {
                  amount
                  currency
                }
                feature {
                  featureUnits
                  featureUnitsPlural
                  displayName
                }
              }
              status
              trialRemainingDays
              billingPeriodRange {
                start
                end
              }
              totalPrice {
                subTotal {
                  amount
                  currency
                }
                total {
                  amount
                  currency
                }
                addonsTotal {
                  amount
                  currency
                }
              }
              addons {
                ...CustomerPortalSubscriptionAddon
              }
              scheduledUpdates {
                ...CustomerPortalSubscriptionScheduledUpdateData
              }
            }

            fragment CustomerPortalSubscriptionPriceFragment on CustomerPortalSubscriptionPrice {
              billingPeriod
              billingModel
              price {
                amount
                currency
              }
              feature {
                id
                refId
                displayName
                featureUnits
                featureUnitsPlural
              }
            }

            fragment CustomerPortalSubscriptionScheduledUpdateData on SubscriptionScheduledUpdate {
              subscriptionScheduleType
              scheduleStatus
              scheduledExecutionTime
              targetPackage {
                id
                refId
                displayName
                pricingType
              }
              scheduleVariables {
                ... on DowngradeChangeVariables {
                  addonRefIds
                  billingPeriod
                  downgradePlanRefId
                }
                ... on BillingPeriodChangeVariables {
                  billingPeriod
                }
                ... on UnitAmountChangeVariables {
                  newUnitAmount
                  featureId
                }
              }
            }

            fragment CustomerResourceFragment on CustomerResource {
              resourceId
            }

            fragment FeatureFragment on EntitlementFeature {
              featureType
              meterType
              featureUnits
              featureUnitsPlural
              description
              displayName
              refId
            }

            fragment FontVariantFragment on FontVariant {
              fontSize
              fontWeight
            }

            fragment ResetPeriodConfigurationFragment on ResetPeriodConfiguration {
              __typename
              ... on MonthlyResetPeriodConfig {
                monthlyAccordingTo
              }
              ... on WeeklyResetPeriodConfig {
                weeklyAccordingTo
              }
            }

            fragment TypographyConfigurationFragment on TypographyConfiguration {
              fontFamily
              h1 {
                ...FontVariantFragment
              }
              h2 {
                ...FontVariantFragment
              }
              h3 {
                ...FontVariantFragment
              }
              body {
                ...FontVariantFragment
              }
            }
            """
        )
        variables: dict[str, object] = {"input": input}
        response = self.execute(query=query, variables=variables)
        data = self.get_data(response)
        return GetCustomerPortalByRefId.parse_obj(data)

    def get_mock_paywall(self, input: GetPaywallInput) -> GetMockPaywall:
        query = gql(
            """
            query GetMockPaywall($input: GetPaywallInput!) {
              mockPaywall(input: $input) {
                plans {
                  ...MockPaywallPlanFragment
                }
                configuration {
                  ...PaywallConfigurationFragment
                }
              }
            }

            fragment FontVariantFragment on FontVariant {
              fontSize
              fontWeight
            }

            fragment LayoutConfigurationFragment on PaywallLayoutConfiguration {
              alignment
              planWidth
              planMargin
              planPadding
            }

            fragment MockPaywallAddonFragment on PaywallAddon {
              refId
              displayName
              description
              additionalMetaData
              billingId
              entitlements {
                ...MockPaywallPackageEntitlementFragment
              }
              prices {
                ...MockPaywallPriceFragment
              }
              pricingType
            }

            fragment MockPaywallPackageEntitlementFragment on Entitlement {
              usageLimit
              hasUnlimitedUsage
              resetPeriod
              hiddenFromWidgets
              displayNameOverride
              feature {
                featureType
                meterType
                featureUnits
                featureUnitsPlural
                displayName
                description
                refId
                additionalMetaData
              }
            }

            fragment MockPaywallPlanFragment on PaywallPlan {
              refId
              description
              displayName
              billingId
              additionalMetaData
              product {
                refId
                displayName
                description
                additionalMetaData
              }
              basePlan {
                refId
                displayName
              }
              entitlements {
                ...MockPaywallPackageEntitlementFragment
              }
              inheritedEntitlements {
                ...MockPaywallPackageEntitlementFragment
              }
              prices {
                ...MockPaywallPriceFragment
              }
              pricingType
              defaultTrialConfig {
                duration
                units
              }
              compatibleAddons {
                ...MockPaywallAddonFragment
              }
            }

            fragment MockPaywallPriceFragment on PaywallPrice {
              billingModel
              billingPeriod
              billingId
              minUnitQuantity
              maxUnitQuantity
              billingCountryCode
              price {
                amount
                currency
              }
              feature {
                refId
                featureUnits
                featureUnitsPlural
                displayName
              }
            }

            fragment PaywallConfigurationFragment on PaywallConfiguration {
              palette {
                primary
                textColor
                backgroundColor
                borderColor
                currentPlanBackground
              }
              typography {
                ...TypographyConfigurationFragment
              }
              layout {
                ...LayoutConfigurationFragment
              }
              customCss
            }

            fragment TypographyConfigurationFragment on TypographyConfiguration {
              fontFamily
              h1 {
                ...FontVariantFragment
              }
              h2 {
                ...FontVariantFragment
              }
              h3 {
                ...FontVariantFragment
              }
              body {
                ...FontVariantFragment
              }
            }
            """
        )
        variables: dict[str, object] = {"input": input}
        response = self.execute(query=query, variables=variables)
        data = self.get_data(response)
        return GetMockPaywall.parse_obj(data)

    def usage_history(self, usage_history_input: UsageHistoryInput) -> UsageHistory:
        query = gql(
            """
            query UsageHistory($usageHistoryInput: UsageHistoryInput!) {
              usageHistory(usageHistoryInput: $usageHistoryInput) {
                ...UsageHistoryFragment
              }
            }

            fragment UsageHistoryFragment on UsageHistory {
              startDate
              endDate
              usageMeasurements {
                date
                value
                isResetPoint
              }
            }
            """
        )
        variables: dict[str, object] = {"usageHistoryInput": usage_history_input}
        response = self.execute(query=query, variables=variables)
        data = self.get_data(response)
        return UsageHistory.parse_obj(data)
