/*
 * 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 { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
  Member,
  Member$inboundSchema,
  Member$Outbound,
  Member$outboundSchema,
} from "./member.js";
import {
  SeatStatus,
  SeatStatus$inboundSchema,
  SeatStatus$outboundSchema,
} from "./seatstatus.js";

export type CustomerSeat = {
  /**
   * Creation timestamp of the object.
   */
  createdAt: Date;
  /**
   * Last modification timestamp of the object.
   */
  modifiedAt: Date | null;
  /**
   * The seat ID
   */
  id: string;
  /**
   * The subscription ID (for recurring seats)
   */
  subscriptionId: string | null;
  /**
   * The order ID (for one-time purchase seats)
   */
  orderId: string | null;
  status: SeatStatus;
  /**
   * The customer ID. When member_model_enabled is true, this is the billing customer (purchaser). When false, this is the seat member customer.
   */
  customerId: string | null;
  /**
   * The member ID of the seat occupant
   */
  memberId: string | null;
  /**
   * The member associated with this seat
   */
  member: Member | null;
  /**
   * Email of the seat member (set when member_model_enabled is true)
   */
  email: string | null;
  /**
   * The assigned customer email
   */
  customerEmail: string | null;
  /**
   * When the invitation token expires
   */
  invitationTokenExpiresAt: Date | null;
  /**
   * When the seat was claimed
   */
  claimedAt: Date | null;
  /**
   * When the seat was revoked
   */
  revokedAt: Date | null;
  /**
   * Additional metadata for the seat
   */
  seatMetadata: { [k: string]: any } | null;
};

/** @internal */
export const CustomerSeat$inboundSchema: z.ZodMiniType<CustomerSeat, unknown> =
  z.pipe(
    z.object({
      created_at: z.pipe(
        z.iso.datetime({ offset: true }),
        z.transform(v => new Date(v)),
      ),
      modified_at: z.nullable(
        z.pipe(z.iso.datetime({ offset: true }), z.transform(v => new Date(v))),
      ),
      id: z.string(),
      subscription_id: z.nullable(z.string()),
      order_id: z.nullable(z.string()),
      status: SeatStatus$inboundSchema,
      customer_id: z.nullable(z.string()),
      member_id: z.nullable(z.string()),
      member: z.nullable(Member$inboundSchema),
      email: z.nullable(z.string()),
      customer_email: z.nullable(z.string()),
      invitation_token_expires_at: z.nullable(
        z.pipe(z.iso.datetime({ offset: true }), z.transform(v => new Date(v))),
      ),
      claimed_at: z.nullable(
        z.pipe(z.iso.datetime({ offset: true }), z.transform(v => new Date(v))),
      ),
      revoked_at: z.nullable(
        z.pipe(z.iso.datetime({ offset: true }), z.transform(v => new Date(v))),
      ),
      seat_metadata: z.nullable(z.record(z.string(), z.any())),
    }),
    z.transform((v) => {
      return remap$(v, {
        "created_at": "createdAt",
        "modified_at": "modifiedAt",
        "subscription_id": "subscriptionId",
        "order_id": "orderId",
        "customer_id": "customerId",
        "member_id": "memberId",
        "customer_email": "customerEmail",
        "invitation_token_expires_at": "invitationTokenExpiresAt",
        "claimed_at": "claimedAt",
        "revoked_at": "revokedAt",
        "seat_metadata": "seatMetadata",
      });
    }),
  );
/** @internal */
export type CustomerSeat$Outbound = {
  created_at: string;
  modified_at: string | null;
  id: string;
  subscription_id: string | null;
  order_id: string | null;
  status: string;
  customer_id: string | null;
  member_id: string | null;
  member: Member$Outbound | null;
  email: string | null;
  customer_email: string | null;
  invitation_token_expires_at: string | null;
  claimed_at: string | null;
  revoked_at: string | null;
  seat_metadata: { [k: string]: any } | null;
};

/** @internal */
export const CustomerSeat$outboundSchema: z.ZodMiniType<
  CustomerSeat$Outbound,
  CustomerSeat
> = z.pipe(
  z.object({
    createdAt: z.pipe(z.date(), z.transform(v => v.toISOString())),
    modifiedAt: z.nullable(z.pipe(z.date(), z.transform(v => v.toISOString()))),
    id: z.string(),
    subscriptionId: z.nullable(z.string()),
    orderId: z.nullable(z.string()),
    status: SeatStatus$outboundSchema,
    customerId: z.nullable(z.string()),
    memberId: z.nullable(z.string()),
    member: z.nullable(Member$outboundSchema),
    email: z.nullable(z.string()),
    customerEmail: z.nullable(z.string()),
    invitationTokenExpiresAt: z.nullable(
      z.pipe(z.date(), z.transform(v => v.toISOString())),
    ),
    claimedAt: z.nullable(z.pipe(z.date(), z.transform(v => v.toISOString()))),
    revokedAt: z.nullable(z.pipe(z.date(), z.transform(v => v.toISOString()))),
    seatMetadata: z.nullable(z.record(z.string(), z.any())),
  }),
  z.transform((v) => {
    return remap$(v, {
      createdAt: "created_at",
      modifiedAt: "modified_at",
      subscriptionId: "subscription_id",
      orderId: "order_id",
      customerId: "customer_id",
      memberId: "member_id",
      customerEmail: "customer_email",
      invitationTokenExpiresAt: "invitation_token_expires_at",
      claimedAt: "claimed_at",
      revokedAt: "revoked_at",
      seatMetadata: "seat_metadata",
    });
  }),
);

export function customerSeatToJSON(customerSeat: CustomerSeat): string {
  return JSON.stringify(CustomerSeat$outboundSchema.parse(customerSeat));
}
export function customerSeatFromJSON(
  jsonString: string,
): SafeParseResult<CustomerSeat, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => CustomerSeat$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'CustomerSeat' from JSON`,
  );
}
