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

import * as z from "zod/v3";
import { safeParse } from "../../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
  CRMCompanyMatch,
  CRMCompanyMatch$inboundSchema,
} from "./crmcompanymatch.js";
import {
  CRMContactMatch,
  CRMContactMatch$inboundSchema,
} from "./crmcontactmatch.js";
import { CRMDealMatch, CRMDealMatch$inboundSchema } from "./crmdealmatch.js";

/**
 * CRM data linked to the meeting. Only returns data from your or your team's linked CRM.
 *
 * @remarks
 * If no CRM is connected for the workspace, the `error` field will be populated.
 */
export type CRMMatches = {
  contacts?: Array<CRMContactMatch> | undefined;
  companies?: Array<CRMCompanyMatch> | undefined;
  deals?: Array<CRMDealMatch> | undefined;
  error?: string | null | undefined;
};

/** @internal */
export const CRMMatches$inboundSchema: z.ZodType<
  CRMMatches,
  z.ZodTypeDef,
  unknown
> = z.object({
  contacts: z.array(CRMContactMatch$inboundSchema).optional(),
  companies: z.array(CRMCompanyMatch$inboundSchema).optional(),
  deals: z.array(CRMDealMatch$inboundSchema).optional(),
  error: z.nullable(z.string()).optional(),
});

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