/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 */

import * as z from "zod/v4-mini";
import { remap as remap$ } from "../../lib/primitives.js";
import {
  CustomerCancellationReason,
  CustomerCancellationReason$outboundSchema,
} from "./customercancellationreason.js";

export type SubscriptionRevoke = {
  /**
   * Customer reason for cancellation.
   *
   * @remarks
   *
   * Helpful to monitor reasons behind churn for future improvements.
   *
   * Only set this in case your own service is requesting the reason from the
   * customer. Or you know based on direct conversations, i.e support, with
   * the customer.
   *
   * * `too_expensive`: Too expensive for the customer.
   * * `missing_features`: Customer is missing certain features.
   * * `switched_service`: Customer switched to another service.
   * * `unused`: Customer is not using it enough.
   * * `customer_service`: Customer is not satisfied with the customer service.
   * * `low_quality`: Customer is unhappy with the quality.
   * * `too_complex`: Customer considers the service too complicated.
   * * `other`: Other reason(s).
   */
  customerCancellationReason?: CustomerCancellationReason | null | undefined;
  /**
   * Customer feedback and why they decided to cancel.
   *
   * @remarks
   *
   * **IMPORTANT:**
   * Do not use this to store internal notes! It's intended to be input
   * from the customer and is therefore also available in their Polar
   * purchases library.
   *
   * Only set this in case your own service is requesting the reason from the
   * customer. Or you copy a message directly from a customer
   * conversation, i.e support.
   */
  customerCancellationComment?: string | null | undefined;
  /**
   * Cancel and revoke an active subscription immediately
   */
  revoke: true;
};

/** @internal */
export type SubscriptionRevoke$Outbound = {
  customer_cancellation_reason?: string | null | undefined;
  customer_cancellation_comment?: string | null | undefined;
  revoke: true;
};

/** @internal */
export const SubscriptionRevoke$outboundSchema: z.ZodMiniType<
  SubscriptionRevoke$Outbound,
  SubscriptionRevoke
> = z.pipe(
  z.object({
    customerCancellationReason: z.optional(
      z.nullable(CustomerCancellationReason$outboundSchema),
    ),
    customerCancellationComment: z.optional(z.nullable(z.string())),
    revoke: z.literal(true),
  }),
  z.transform((v) => {
    return remap$(v, {
      customerCancellationReason: "customer_cancellation_reason",
      customerCancellationComment: "customer_cancellation_comment",
    });
  }),
);

export function subscriptionRevokeToJSON(
  subscriptionRevoke: SubscriptionRevoke,
): string {
  return JSON.stringify(
    SubscriptionRevoke$outboundSchema.parse(subscriptionRevoke),
  );
}
