/*
 * 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 { ClosedEnum } from "../types/enums.js";
import { Result as SafeParseResult } from "../types/fp.js";
import * as types from "../types/primitives.js";
import { smartUnion } from "../types/smartUnion.js";
import { SDKValidationError } from "./sdkvalidationerror.js";

export type TestDrainSchemas = {
  version: string;
};

export const TestDrainDeliveryDrainsRequestEncoding = {
  Json: "json",
  Ndjson: "ndjson",
} as const;
export type TestDrainDeliveryDrainsRequestEncoding = ClosedEnum<
  typeof TestDrainDeliveryDrainsRequestEncoding
>;

export const TestDrainDeliveryDrainsCompression = {
  None: "none",
} as const;
export type TestDrainDeliveryDrainsCompression = ClosedEnum<
  typeof TestDrainDeliveryDrainsCompression
>;

export const TestDrainDeliveryFileStructure = {
  Hive: "hive",
} as const;
export type TestDrainDeliveryFileStructure = ClosedEnum<
  typeof TestDrainDeliveryFileStructure
>;

export const TestDrainDeliveryServerSideEncryption = {
  Aes256: "AES256",
  AwsKms: "aws:kms",
  AwsKmsDsse: "aws:kms:dsse",
} as const;
export type TestDrainDeliveryServerSideEncryption = ClosedEnum<
  typeof TestDrainDeliveryServerSideEncryption
>;

export const TestDrainDeliveryObjectAcl = {
  Private: "private",
  BucketOwnerRead: "bucket-owner-read",
  BucketOwnerFullControl: "bucket-owner-full-control",
} as const;
export type TestDrainDeliveryObjectAcl = ClosedEnum<
  typeof TestDrainDeliveryObjectAcl
>;

export type TestDrainDelivery3 = {
  type: string;
  endpoint: string;
  encoding: TestDrainDeliveryDrainsRequestEncoding;
  compression: TestDrainDeliveryDrainsCompression;
  fileStructure: TestDrainDeliveryFileStructure;
  roleArn: string;
  region: string;
  serverSideEncryption?: TestDrainDeliveryServerSideEncryption | undefined;
  objectAcl?: TestDrainDeliveryObjectAcl | undefined;
};

export type TestDrainEndpoint1 = {
  traces: string;
};

export type TestDrainDeliveryEndpoint = TestDrainEndpoint1;

export const TestDrainDeliveryDrainsEncoding = {
  Proto: "proto",
  Json: "json",
} as const;
export type TestDrainDeliveryDrainsEncoding = ClosedEnum<
  typeof TestDrainDeliveryDrainsEncoding
>;

export type TestDrainDelivery2 = {
  type: string;
  endpoint: TestDrainEndpoint1;
  encoding: TestDrainDeliveryDrainsEncoding;
  headers: { [k: string]: string };
  secret?: string | undefined;
};

export const TestDrainDeliveryCompression = {
  Gzip: "gzip",
  None: "none",
} as const;
export type TestDrainDeliveryCompression = ClosedEnum<
  typeof TestDrainDeliveryCompression
>;

export const TestDrainDeliveryEncoding = {
  Json: "json",
  Ndjson: "ndjson",
} as const;
export type TestDrainDeliveryEncoding = ClosedEnum<
  typeof TestDrainDeliveryEncoding
>;

export type TestDrainDelivery1 = {
  type: string;
  endpoint: string;
  compression?: TestDrainDeliveryCompression | undefined;
  encoding: TestDrainDeliveryEncoding;
  headers: { [k: string]: string };
  secret?: string | undefined;
};

export type TestDrainDelivery =
  | TestDrainDelivery3
  | TestDrainDelivery1
  | TestDrainDelivery2;

export type TestDrainRequestBody = {
  schemas: { [k: string]: TestDrainSchemas };
  delivery: TestDrainDelivery3 | TestDrainDelivery1 | TestDrainDelivery2;
};

export type TestDrainRequest = {
  /**
   * The Team identifier to perform the request on behalf of.
   */
  teamId?: string | undefined;
  /**
   * The Team slug to perform the request on behalf of.
   */
  slug?: string | undefined;
  requestBody?: TestDrainRequestBody | undefined;
};

export type TestDrainResponseBody2 = {
  status: string;
  error: string;
  endpoint: string;
};

export type TestDrainResponseBody1 = {};

export type TestDrainResponseBody =
  | TestDrainResponseBody2
  | TestDrainResponseBody1;

/** @internal */
export type TestDrainSchemas$Outbound = {
  version: string;
};

/** @internal */
export const TestDrainSchemas$outboundSchema: z.ZodType<
  TestDrainSchemas$Outbound,
  z.ZodTypeDef,
  TestDrainSchemas
> = z.object({
  version: z.string(),
});

export function testDrainSchemasToJSON(
  testDrainSchemas: TestDrainSchemas,
): string {
  return JSON.stringify(
    TestDrainSchemas$outboundSchema.parse(testDrainSchemas),
  );
}

/** @internal */
export const TestDrainDeliveryDrainsRequestEncoding$outboundSchema:
  z.ZodNativeEnum<typeof TestDrainDeliveryDrainsRequestEncoding> = z.nativeEnum(
    TestDrainDeliveryDrainsRequestEncoding,
  );

/** @internal */
export const TestDrainDeliveryDrainsCompression$outboundSchema: z.ZodNativeEnum<
  typeof TestDrainDeliveryDrainsCompression
> = z.nativeEnum(TestDrainDeliveryDrainsCompression);

/** @internal */
export const TestDrainDeliveryFileStructure$outboundSchema: z.ZodNativeEnum<
  typeof TestDrainDeliveryFileStructure
> = z.nativeEnum(TestDrainDeliveryFileStructure);

/** @internal */
export const TestDrainDeliveryServerSideEncryption$outboundSchema:
  z.ZodNativeEnum<typeof TestDrainDeliveryServerSideEncryption> = z.nativeEnum(
    TestDrainDeliveryServerSideEncryption,
  );

/** @internal */
export const TestDrainDeliveryObjectAcl$outboundSchema: z.ZodNativeEnum<
  typeof TestDrainDeliveryObjectAcl
> = z.nativeEnum(TestDrainDeliveryObjectAcl);

/** @internal */
export type TestDrainDelivery3$Outbound = {
  type: string;
  endpoint: string;
  encoding: string;
  compression: string;
  fileStructure: string;
  roleArn: string;
  region: string;
  serverSideEncryption?: string | undefined;
  objectAcl?: string | undefined;
};

/** @internal */
export const TestDrainDelivery3$outboundSchema: z.ZodType<
  TestDrainDelivery3$Outbound,
  z.ZodTypeDef,
  TestDrainDelivery3
> = z.object({
  type: z.string(),
  endpoint: z.string(),
  encoding: TestDrainDeliveryDrainsRequestEncoding$outboundSchema,
  compression: TestDrainDeliveryDrainsCompression$outboundSchema,
  fileStructure: TestDrainDeliveryFileStructure$outboundSchema,
  roleArn: z.string(),
  region: z.string(),
  serverSideEncryption: TestDrainDeliveryServerSideEncryption$outboundSchema
    .optional(),
  objectAcl: TestDrainDeliveryObjectAcl$outboundSchema.optional(),
});

export function testDrainDelivery3ToJSON(
  testDrainDelivery3: TestDrainDelivery3,
): string {
  return JSON.stringify(
    TestDrainDelivery3$outboundSchema.parse(testDrainDelivery3),
  );
}

/** @internal */
export type TestDrainEndpoint1$Outbound = {
  traces: string;
};

/** @internal */
export const TestDrainEndpoint1$outboundSchema: z.ZodType<
  TestDrainEndpoint1$Outbound,
  z.ZodTypeDef,
  TestDrainEndpoint1
> = z.object({
  traces: z.string(),
});

export function testDrainEndpoint1ToJSON(
  testDrainEndpoint1: TestDrainEndpoint1,
): string {
  return JSON.stringify(
    TestDrainEndpoint1$outboundSchema.parse(testDrainEndpoint1),
  );
}

/** @internal */
export type TestDrainDeliveryEndpoint$Outbound = TestDrainEndpoint1$Outbound;

/** @internal */
export const TestDrainDeliveryEndpoint$outboundSchema: z.ZodType<
  TestDrainDeliveryEndpoint$Outbound,
  z.ZodTypeDef,
  TestDrainDeliveryEndpoint
> = z.lazy(() => TestDrainEndpoint1$outboundSchema);

export function testDrainDeliveryEndpointToJSON(
  testDrainDeliveryEndpoint: TestDrainDeliveryEndpoint,
): string {
  return JSON.stringify(
    TestDrainDeliveryEndpoint$outboundSchema.parse(testDrainDeliveryEndpoint),
  );
}

/** @internal */
export const TestDrainDeliveryDrainsEncoding$outboundSchema: z.ZodNativeEnum<
  typeof TestDrainDeliveryDrainsEncoding
> = z.nativeEnum(TestDrainDeliveryDrainsEncoding);

/** @internal */
export type TestDrainDelivery2$Outbound = {
  type: string;
  endpoint: TestDrainEndpoint1$Outbound;
  encoding: string;
  headers: { [k: string]: string };
  secret?: string | undefined;
};

/** @internal */
export const TestDrainDelivery2$outboundSchema: z.ZodType<
  TestDrainDelivery2$Outbound,
  z.ZodTypeDef,
  TestDrainDelivery2
> = z.object({
  type: z.string(),
  endpoint: z.lazy(() => TestDrainEndpoint1$outboundSchema),
  encoding: TestDrainDeliveryDrainsEncoding$outboundSchema,
  headers: z.record(z.string()),
  secret: z.string().optional(),
});

export function testDrainDelivery2ToJSON(
  testDrainDelivery2: TestDrainDelivery2,
): string {
  return JSON.stringify(
    TestDrainDelivery2$outboundSchema.parse(testDrainDelivery2),
  );
}

/** @internal */
export const TestDrainDeliveryCompression$outboundSchema: z.ZodNativeEnum<
  typeof TestDrainDeliveryCompression
> = z.nativeEnum(TestDrainDeliveryCompression);

/** @internal */
export const TestDrainDeliveryEncoding$outboundSchema: z.ZodNativeEnum<
  typeof TestDrainDeliveryEncoding
> = z.nativeEnum(TestDrainDeliveryEncoding);

/** @internal */
export type TestDrainDelivery1$Outbound = {
  type: string;
  endpoint: string;
  compression?: string | undefined;
  encoding: string;
  headers: { [k: string]: string };
  secret?: string | undefined;
};

/** @internal */
export const TestDrainDelivery1$outboundSchema: z.ZodType<
  TestDrainDelivery1$Outbound,
  z.ZodTypeDef,
  TestDrainDelivery1
> = z.object({
  type: z.string(),
  endpoint: z.string(),
  compression: TestDrainDeliveryCompression$outboundSchema.optional(),
  encoding: TestDrainDeliveryEncoding$outboundSchema,
  headers: z.record(z.string()),
  secret: z.string().optional(),
});

export function testDrainDelivery1ToJSON(
  testDrainDelivery1: TestDrainDelivery1,
): string {
  return JSON.stringify(
    TestDrainDelivery1$outboundSchema.parse(testDrainDelivery1),
  );
}

/** @internal */
export type TestDrainDelivery$Outbound =
  | TestDrainDelivery3$Outbound
  | TestDrainDelivery1$Outbound
  | TestDrainDelivery2$Outbound;

/** @internal */
export const TestDrainDelivery$outboundSchema: z.ZodType<
  TestDrainDelivery$Outbound,
  z.ZodTypeDef,
  TestDrainDelivery
> = smartUnion([
  z.lazy(() => TestDrainDelivery3$outboundSchema),
  z.lazy(() => TestDrainDelivery1$outboundSchema),
  z.lazy(() => TestDrainDelivery2$outboundSchema),
]);

export function testDrainDeliveryToJSON(
  testDrainDelivery: TestDrainDelivery,
): string {
  return JSON.stringify(
    TestDrainDelivery$outboundSchema.parse(testDrainDelivery),
  );
}

/** @internal */
export type TestDrainRequestBody$Outbound = {
  schemas: { [k: string]: TestDrainSchemas$Outbound };
  delivery:
    | TestDrainDelivery3$Outbound
    | TestDrainDelivery1$Outbound
    | TestDrainDelivery2$Outbound;
};

/** @internal */
export const TestDrainRequestBody$outboundSchema: z.ZodType<
  TestDrainRequestBody$Outbound,
  z.ZodTypeDef,
  TestDrainRequestBody
> = z.object({
  schemas: z.record(z.lazy(() => TestDrainSchemas$outboundSchema)),
  delivery: smartUnion([
    z.lazy(() => TestDrainDelivery3$outboundSchema),
    z.lazy(() => TestDrainDelivery1$outboundSchema),
    z.lazy(() => TestDrainDelivery2$outboundSchema),
  ]),
});

export function testDrainRequestBodyToJSON(
  testDrainRequestBody: TestDrainRequestBody,
): string {
  return JSON.stringify(
    TestDrainRequestBody$outboundSchema.parse(testDrainRequestBody),
  );
}

/** @internal */
export type TestDrainRequest$Outbound = {
  teamId?: string | undefined;
  slug?: string | undefined;
  RequestBody?: TestDrainRequestBody$Outbound | undefined;
};

/** @internal */
export const TestDrainRequest$outboundSchema: z.ZodType<
  TestDrainRequest$Outbound,
  z.ZodTypeDef,
  TestDrainRequest
> = z.object({
  teamId: z.string().optional(),
  slug: z.string().optional(),
  requestBody: z.lazy(() => TestDrainRequestBody$outboundSchema).optional(),
}).transform((v) => {
  return remap$(v, {
    requestBody: "RequestBody",
  });
});

export function testDrainRequestToJSON(
  testDrainRequest: TestDrainRequest,
): string {
  return JSON.stringify(
    TestDrainRequest$outboundSchema.parse(testDrainRequest),
  );
}

/** @internal */
export const TestDrainResponseBody2$inboundSchema: z.ZodType<
  TestDrainResponseBody2,
  z.ZodTypeDef,
  unknown
> = z.object({
  status: types.string(),
  error: types.string(),
  endpoint: types.string(),
});

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

/** @internal */
export const TestDrainResponseBody1$inboundSchema: z.ZodType<
  TestDrainResponseBody1,
  z.ZodTypeDef,
  unknown
> = z.object({});

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

/** @internal */
export const TestDrainResponseBody$inboundSchema: z.ZodType<
  TestDrainResponseBody,
  z.ZodTypeDef,
  unknown
> = smartUnion([
  z.lazy(() => TestDrainResponseBody2$inboundSchema),
  z.lazy(() => TestDrainResponseBody1$inboundSchema),
]);

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