/*
 * 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 * as types from "../types/primitives.js";
import {
  ConnectConnector,
  ConnectConnector$inboundSchema,
} from "./connectconnector.js";
import {
  ConnectReconsent,
  ConnectReconsent$inboundSchema,
} from "./connectreconsent.js";
import {
  ConnectServiceSync,
  ConnectServiceSync$inboundSchema,
} from "./connectservicesync.js";
import { SDKValidationError } from "./sdkvalidationerror.js";

/**
 * Updated connector and any required provider follow-up actions.
 */
export type ConnectConnectorUpdateResult = {
  /**
   * A connector that defines how Vercel accesses an external service.
   */
  connector: ConnectConnector;
  /**
   * When true, prompt a team owner or administrator to reinstall the connector before relying on the change.
   */
  reinstallNeeded?: boolean | undefined;
  /**
   * Existing authorizations no longer cover the connector's configured scopes, so they must be re-authorized.
   */
  reconsentNeeded?: ConnectReconsent | undefined;
  /**
   * Provider-side configuration synchronization result.
   */
  serviceSync?: ConnectServiceSync | undefined;
};

/** @internal */
export const ConnectConnectorUpdateResult$inboundSchema: z.ZodType<
  ConnectConnectorUpdateResult,
  z.ZodTypeDef,
  unknown
> = z.object({
  connector: ConnectConnector$inboundSchema,
  reinstallNeeded: types.optional(types.boolean()),
  reconsentNeeded: types.optional(ConnectReconsent$inboundSchema),
  serviceSync: types.optional(ConnectServiceSync$inboundSchema),
});

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