/*
 * 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 {
  BenefitGrantError,
  BenefitGrantError$inboundSchema,
} from "./benefitgranterror.js";
import {
  BenefitGrantLicenseKeysProperties,
  BenefitGrantLicenseKeysProperties$inboundSchema,
} from "./benefitgrantlicensekeysproperties.js";
import {
  BenefitLicenseKeysSubscriber,
  BenefitLicenseKeysSubscriber$inboundSchema,
} from "./benefitlicensekeyssubscriber.js";
import {
  CustomerPortalCustomer,
  CustomerPortalCustomer$inboundSchema,
} from "./customerportalcustomer.js";

export type CustomerBenefitGrantLicenseKeys = {
  /**
   * Creation timestamp of the object.
   */
  createdAt: Date;
  /**
   * Last modification timestamp of the object.
   */
  modifiedAt: Date | null;
  /**
   * The ID of the object.
   */
  id: string;
  grantedAt: Date | null;
  revokedAt: Date | null;
  customerId: string;
  memberId?: string | null | undefined;
  benefitId: string;
  subscriptionId: string | null;
  orderId: string | null;
  isGranted: boolean;
  isRevoked: boolean;
  error?: BenefitGrantError | null | undefined;
  customer: CustomerPortalCustomer;
  benefit: BenefitLicenseKeysSubscriber;
  properties: BenefitGrantLicenseKeysProperties;
};

/** @internal */
export const CustomerBenefitGrantLicenseKeys$inboundSchema: z.ZodMiniType<
  CustomerBenefitGrantLicenseKeys,
  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(),
    granted_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))),
    ),
    customer_id: z.string(),
    member_id: z.optional(z.nullable(z.string())),
    benefit_id: z.string(),
    subscription_id: z.nullable(z.string()),
    order_id: z.nullable(z.string()),
    is_granted: z.boolean(),
    is_revoked: z.boolean(),
    error: z.optional(z.nullable(BenefitGrantError$inboundSchema)),
    customer: CustomerPortalCustomer$inboundSchema,
    benefit: BenefitLicenseKeysSubscriber$inboundSchema,
    properties: BenefitGrantLicenseKeysProperties$inboundSchema,
  }),
  z.transform((v) => {
    return remap$(v, {
      "created_at": "createdAt",
      "modified_at": "modifiedAt",
      "granted_at": "grantedAt",
      "revoked_at": "revokedAt",
      "customer_id": "customerId",
      "member_id": "memberId",
      "benefit_id": "benefitId",
      "subscription_id": "subscriptionId",
      "order_id": "orderId",
      "is_granted": "isGranted",
      "is_revoked": "isRevoked",
    });
  }),
);

export function customerBenefitGrantLicenseKeysFromJSON(
  jsonString: string,
): SafeParseResult<CustomerBenefitGrantLicenseKeys, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => CustomerBenefitGrantLicenseKeys$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'CustomerBenefitGrantLicenseKeys' from JSON`,
  );
}
