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

import * as z from "zod/v3";
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 {
  Link,
  Link$inboundSchema,
  Link$Outbound,
  Link$outboundSchema,
} from "./link.js";

export type AuthorizedAppDataRep = {
  links?: { [k: string]: Link } | undefined;
  /**
   * The ID of the authorized application
   */
  id?: string | undefined;
  /**
   * Whether the application is authorized through SCIM
   */
  isScim?: boolean | undefined;
  /**
   * The authorized application name
   */
  name?: string | undefined;
  /**
   * The icon for this authorized application, if it has one
   */
  iconUrl?: string | undefined;
  /**
   * The name of the maintainer for this authorized application
   */
  maintainerName?: string | undefined;
  /**
   * Whether this application acted on behalf of the member in this entry. When true, the member and the application are co-authors of the change rather than the member acting alone. Omitted for applications that act on their own.
   */
  isAgent?: boolean | undefined;
};

/** @internal */
export const AuthorizedAppDataRep$inboundSchema: z.ZodType<
  AuthorizedAppDataRep,
  z.ZodTypeDef,
  unknown
> = z.object({
  _links: z.record(Link$inboundSchema).optional(),
  _id: z.string().optional(),
  isScim: z.boolean().optional(),
  name: z.string().optional(),
  iconUrl: z.string().optional(),
  maintainerName: z.string().optional(),
  isAgent: z.boolean().optional(),
}).transform((v) => {
  return remap$(v, {
    "_links": "links",
    "_id": "id",
  });
});
/** @internal */
export type AuthorizedAppDataRep$Outbound = {
  _links?: { [k: string]: Link$Outbound } | undefined;
  _id?: string | undefined;
  isScim?: boolean | undefined;
  name?: string | undefined;
  iconUrl?: string | undefined;
  maintainerName?: string | undefined;
  isAgent?: boolean | undefined;
};

/** @internal */
export const AuthorizedAppDataRep$outboundSchema: z.ZodType<
  AuthorizedAppDataRep$Outbound,
  z.ZodTypeDef,
  AuthorizedAppDataRep
> = z.object({
  links: z.record(Link$outboundSchema).optional(),
  id: z.string().optional(),
  isScim: z.boolean().optional(),
  name: z.string().optional(),
  iconUrl: z.string().optional(),
  maintainerName: z.string().optional(),
  isAgent: z.boolean().optional(),
}).transform((v) => {
  return remap$(v, {
    links: "_links",
    id: "_id",
  });
});

export function authorizedAppDataRepToJSON(
  authorizedAppDataRep: AuthorizedAppDataRep,
): string {
  return JSON.stringify(
    AuthorizedAppDataRep$outboundSchema.parse(authorizedAppDataRep),
  );
}
export function authorizedAppDataRepFromJSON(
  jsonString: string,
): SafeParseResult<AuthorizedAppDataRep, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => AuthorizedAppDataRep$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'AuthorizedAppDataRep' from JSON`,
  );
}
