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

import * as z from "zod";
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";

export const GetCompanionsDataServerList = [
  "https://plex.tv/api/v2",
] as const;

export type ResponseBody = {
  identifier: string;
  baseURL: string;
  title: string;
  linkURL: string;
  provides: string;
  /**
   * The plex authtoken used to identify with
   */
  token: string;
};

export type GetCompanionsDataResponse = {
  /**
   * HTTP response content type for this operation
   */
  contentType: string;
  /**
   * HTTP response status code for this operation
   */
  statusCode: number;
  /**
   * Raw HTTP response; suitable for custom response parsing
   */
  rawResponse: Response;
  /**
   * Companions Data
   */
  responseBodies?: Array<ResponseBody> | undefined;
};

/** @internal */
export const ResponseBody$inboundSchema: z.ZodType<
  ResponseBody,
  z.ZodTypeDef,
  unknown
> = z.object({
  identifier: z.string(),
  baseURL: z.string(),
  title: z.string(),
  linkURL: z.string(),
  provides: z.string(),
  token: z.string(),
});

/** @internal */
export type ResponseBody$Outbound = {
  identifier: string;
  baseURL: string;
  title: string;
  linkURL: string;
  provides: string;
  token: string;
};

/** @internal */
export const ResponseBody$outboundSchema: z.ZodType<
  ResponseBody$Outbound,
  z.ZodTypeDef,
  ResponseBody
> = z.object({
  identifier: z.string(),
  baseURL: z.string(),
  title: z.string(),
  linkURL: z.string(),
  provides: z.string(),
  token: z.string(),
});

/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export namespace ResponseBody$ {
  /** @deprecated use `ResponseBody$inboundSchema` instead. */
  export const inboundSchema = ResponseBody$inboundSchema;
  /** @deprecated use `ResponseBody$outboundSchema` instead. */
  export const outboundSchema = ResponseBody$outboundSchema;
  /** @deprecated use `ResponseBody$Outbound` instead. */
  export type Outbound = ResponseBody$Outbound;
}

export function responseBodyToJSON(responseBody: ResponseBody): string {
  return JSON.stringify(ResponseBody$outboundSchema.parse(responseBody));
}

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

/** @internal */
export const GetCompanionsDataResponse$inboundSchema: z.ZodType<
  GetCompanionsDataResponse,
  z.ZodTypeDef,
  unknown
> = z.object({
  ContentType: z.string(),
  StatusCode: z.number().int(),
  RawResponse: z.instanceof(Response),
  responseBodies: z.array(z.lazy(() => ResponseBody$inboundSchema)).optional(),
}).transform((v) => {
  return remap$(v, {
    "ContentType": "contentType",
    "StatusCode": "statusCode",
    "RawResponse": "rawResponse",
  });
});

/** @internal */
export type GetCompanionsDataResponse$Outbound = {
  ContentType: string;
  StatusCode: number;
  RawResponse: never;
  responseBodies?: Array<ResponseBody$Outbound> | undefined;
};

/** @internal */
export const GetCompanionsDataResponse$outboundSchema: z.ZodType<
  GetCompanionsDataResponse$Outbound,
  z.ZodTypeDef,
  GetCompanionsDataResponse
> = z.object({
  contentType: z.string(),
  statusCode: z.number().int(),
  rawResponse: z.instanceof(Response).transform(() => {
    throw new Error("Response cannot be serialized");
  }),
  responseBodies: z.array(z.lazy(() => ResponseBody$outboundSchema)).optional(),
}).transform((v) => {
  return remap$(v, {
    contentType: "ContentType",
    statusCode: "StatusCode",
    rawResponse: "RawResponse",
  });
});

/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export namespace GetCompanionsDataResponse$ {
  /** @deprecated use `GetCompanionsDataResponse$inboundSchema` instead. */
  export const inboundSchema = GetCompanionsDataResponse$inboundSchema;
  /** @deprecated use `GetCompanionsDataResponse$outboundSchema` instead. */
  export const outboundSchema = GetCompanionsDataResponse$outboundSchema;
  /** @deprecated use `GetCompanionsDataResponse$Outbound` instead. */
  export type Outbound = GetCompanionsDataResponse$Outbound;
}

export function getCompanionsDataResponseToJSON(
  getCompanionsDataResponse: GetCompanionsDataResponse,
): string {
  return JSON.stringify(
    GetCompanionsDataResponse$outboundSchema.parse(getCompanionsDataResponse),
  );
}

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