/*
 * 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 {
  BenefitGrantSlackSharedChannelProperties,
  BenefitGrantSlackSharedChannelProperties$inboundSchema,
} from "./benefitgrantslacksharedchannelproperties.js";
import {
  BenefitSlackSharedChannelSubscriber,
  BenefitSlackSharedChannelSubscriber$inboundSchema,
} from "./benefitslacksharedchannelsubscriber.js";
import {
  CustomerPortalCustomer,
  CustomerPortalCustomer$inboundSchema,
} from "./customerportalcustomer.js";

export type CustomerBenefitGrantSlackSharedChannel = {
  /**
   * 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: BenefitSlackSharedChannelSubscriber;
  properties: BenefitGrantSlackSharedChannelProperties;
};

/** @internal */
export const CustomerBenefitGrantSlackSharedChannel$inboundSchema:
  z.ZodMiniType<CustomerBenefitGrantSlackSharedChannel, 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: BenefitSlackSharedChannelSubscriber$inboundSchema,
      properties: BenefitGrantSlackSharedChannelProperties$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 customerBenefitGrantSlackSharedChannelFromJSON(
  jsonString: string,
): SafeParseResult<CustomerBenefitGrantSlackSharedChannel, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) =>
      CustomerBenefitGrantSlackSharedChannel$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'CustomerBenefitGrantSlackSharedChannel' from JSON`,
  );
}
