/*
 * 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 { MemberRole, MemberRole$inboundSchema } from "./memberrole.js";

/**
 * A member of the customer's team as seen in the customer portal.
 */
export type CustomerPortalMember = {
  /**
   * Creation timestamp of the object.
   */
  createdAt: Date;
  /**
   * Last modification timestamp of the object.
   */
  modifiedAt: Date | null;
  /**
   * The ID of the object.
   */
  id: string;
  /**
   * The email address of the member.
   */
  email: string;
  /**
   * The name of the member.
   */
  name: string | null;
  role: MemberRole;
};

/** @internal */
export const CustomerPortalMember$inboundSchema: z.ZodMiniType<
  CustomerPortalMember,
  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(),
    email: z.string(),
    name: z.nullable(z.string()),
    role: MemberRole$inboundSchema,
  }),
  z.transform((v) => {
    return remap$(v, {
      "created_at": "createdAt",
      "modified_at": "modifiedAt",
    });
  }),
);

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