/*
 * 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 {
  AuthorizedAppDataRep,
  AuthorizedAppDataRep$inboundSchema,
  AuthorizedAppDataRep$Outbound,
  AuthorizedAppDataRep$outboundSchema,
} from "./authorizedappdatarep.js";
import {
  Link,
  Link$inboundSchema,
  Link$Outbound,
  Link$outboundSchema,
} from "./link.js";
import {
  MemberDataRep,
  MemberDataRep$inboundSchema,
  MemberDataRep$Outbound,
  MemberDataRep$outboundSchema,
} from "./memberdatarep.js";
import {
  ParentResourceRep,
  ParentResourceRep$inboundSchema,
  ParentResourceRep$Outbound,
  ParentResourceRep$outboundSchema,
} from "./parentresourcerep.js";
import {
  RelatedAIConfig,
  RelatedAIConfig$inboundSchema,
  RelatedAIConfig$Outbound,
  RelatedAIConfig$outboundSchema,
} from "./relatedaiconfig.js";
import {
  RelatedExperiment,
  RelatedExperiment$inboundSchema,
  RelatedExperiment$Outbound,
  RelatedExperiment$outboundSchema,
} from "./relatedexperiment.js";
import {
  RelatedFlag,
  RelatedFlag$inboundSchema,
  RelatedFlag$Outbound,
  RelatedFlag$outboundSchema,
} from "./relatedflag.js";
import {
  ResourceAccess,
  ResourceAccess$inboundSchema,
  ResourceAccess$Outbound,
  ResourceAccess$outboundSchema,
} from "./resourceaccess.js";
import {
  SubjectDataRep,
  SubjectDataRep$inboundSchema,
  SubjectDataRep$Outbound,
  SubjectDataRep$outboundSchema,
} from "./subjectdatarep.js";
import {
  TargetResourceRep,
  TargetResourceRep$inboundSchema,
  TargetResourceRep$Outbound,
  TargetResourceRep$outboundSchema,
} from "./targetresourcerep.js";
import {
  TokenSummary,
  TokenSummary$inboundSchema,
  TokenSummary$Outbound,
  TokenSummary$outboundSchema,
} from "./tokensummary.js";

export type AuditLogEntryListingRep = {
  /**
   * The location and content type of related resources
   */
  links: { [k: string]: Link };
  /**
   * The ID of the audit log entry
   */
  id: string;
  /**
   * The ID of the account to which this audit log entry belongs
   */
  accountId: string;
  date: number;
  /**
   * Details on the actions performed and resources acted on in this audit log entry
   */
  accesses: Array<ResourceAccess>;
  kind: string;
  /**
   * The name of the resource this audit log entry refers to
   */
  name: string;
  /**
   * Description of the change recorded in the audit log entry
   */
  description: string;
  /**
   * Shorter version of the change recorded in the audit log entry
   */
  shortDescription: string;
  /**
   * Optional comment for the audit log entry
   */
  comment?: string | undefined;
  relatedFlag?: RelatedFlag | undefined;
  relatedExperiment?: RelatedExperiment | undefined;
  relatedAIConfig?: RelatedAIConfig | undefined;
  subject?: SubjectDataRep | undefined;
  member?: MemberDataRep | undefined;
  token?: TokenSummary | undefined;
  app?: AuthorizedAppDataRep | undefined;
  /**
   * The action and resource recorded in this audit log entry
   */
  titleVerb?: string | undefined;
  /**
   * A description of what occurred, in the format <code>member</code> <code>titleVerb</code> <code>target</code>
   */
  title?: string | undefined;
  target?: TargetResourceRep | undefined;
  parent?: ParentResourceRep | undefined;
};

/** @internal */
export const AuditLogEntryListingRep$inboundSchema: z.ZodType<
  AuditLogEntryListingRep,
  z.ZodTypeDef,
  unknown
> = z.object({
  _links: z.record(Link$inboundSchema),
  _id: z.string(),
  _accountId: z.string(),
  date: z.number().int(),
  accesses: z.array(ResourceAccess$inboundSchema),
  kind: z.string(),
  name: z.string(),
  description: z.string(),
  shortDescription: z.string(),
  comment: z.string().optional(),
  relatedFlag: RelatedFlag$inboundSchema.optional(),
  relatedExperiment: RelatedExperiment$inboundSchema.optional(),
  relatedAIConfig: RelatedAIConfig$inboundSchema.optional(),
  subject: SubjectDataRep$inboundSchema.optional(),
  member: MemberDataRep$inboundSchema.optional(),
  token: TokenSummary$inboundSchema.optional(),
  app: AuthorizedAppDataRep$inboundSchema.optional(),
  titleVerb: z.string().optional(),
  title: z.string().optional(),
  target: TargetResourceRep$inboundSchema.optional(),
  parent: ParentResourceRep$inboundSchema.optional(),
}).transform((v) => {
  return remap$(v, {
    "_links": "links",
    "_id": "id",
    "_accountId": "accountId",
  });
});
/** @internal */
export type AuditLogEntryListingRep$Outbound = {
  _links: { [k: string]: Link$Outbound };
  _id: string;
  _accountId: string;
  date: number;
  accesses: Array<ResourceAccess$Outbound>;
  kind: string;
  name: string;
  description: string;
  shortDescription: string;
  comment?: string | undefined;
  relatedFlag?: RelatedFlag$Outbound | undefined;
  relatedExperiment?: RelatedExperiment$Outbound | undefined;
  relatedAIConfig?: RelatedAIConfig$Outbound | undefined;
  subject?: SubjectDataRep$Outbound | undefined;
  member?: MemberDataRep$Outbound | undefined;
  token?: TokenSummary$Outbound | undefined;
  app?: AuthorizedAppDataRep$Outbound | undefined;
  titleVerb?: string | undefined;
  title?: string | undefined;
  target?: TargetResourceRep$Outbound | undefined;
  parent?: ParentResourceRep$Outbound | undefined;
};

/** @internal */
export const AuditLogEntryListingRep$outboundSchema: z.ZodType<
  AuditLogEntryListingRep$Outbound,
  z.ZodTypeDef,
  AuditLogEntryListingRep
> = z.object({
  links: z.record(Link$outboundSchema),
  id: z.string(),
  accountId: z.string(),
  date: z.number().int(),
  accesses: z.array(ResourceAccess$outboundSchema),
  kind: z.string(),
  name: z.string(),
  description: z.string(),
  shortDescription: z.string(),
  comment: z.string().optional(),
  relatedFlag: RelatedFlag$outboundSchema.optional(),
  relatedExperiment: RelatedExperiment$outboundSchema.optional(),
  relatedAIConfig: RelatedAIConfig$outboundSchema.optional(),
  subject: SubjectDataRep$outboundSchema.optional(),
  member: MemberDataRep$outboundSchema.optional(),
  token: TokenSummary$outboundSchema.optional(),
  app: AuthorizedAppDataRep$outboundSchema.optional(),
  titleVerb: z.string().optional(),
  title: z.string().optional(),
  target: TargetResourceRep$outboundSchema.optional(),
  parent: ParentResourceRep$outboundSchema.optional(),
}).transform((v) => {
  return remap$(v, {
    links: "_links",
    id: "_id",
    accountId: "_accountId",
  });
});

export function auditLogEntryListingRepToJSON(
  auditLogEntryListingRep: AuditLogEntryListingRep,
): string {
  return JSON.stringify(
    AuditLogEntryListingRep$outboundSchema.parse(auditLogEntryListingRep),
  );
}
export function auditLogEntryListingRepFromJSON(
  jsonString: string,
): SafeParseResult<AuditLogEntryListingRep, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => AuditLogEntryListingRep$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'AuditLogEntryListingRep' from JSON`,
  );
}
