/*
 * 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 "./sdkvalidationerror.js";

export type ClearPlaylistContentsPlaylistsErrors = {
  code?: number | undefined;
  message?: string | undefined;
  status?: number | undefined;
};

/**
 * Unauthorized - Returned if the X-Plex-Token is missing from the header or query.
 */
export type ClearPlaylistContentsUnauthorizedData = {
  errors?: Array<ClearPlaylistContentsPlaylistsErrors> | undefined;
  /**
   * Raw HTTP response; suitable for custom response parsing
   */
  rawResponse?: Response | undefined;
};

/**
 * Unauthorized - Returned if the X-Plex-Token is missing from the header or query.
 */
export class ClearPlaylistContentsUnauthorized extends Error {
  errors?: Array<ClearPlaylistContentsPlaylistsErrors> | undefined;
  /**
   * Raw HTTP response; suitable for custom response parsing
   */
  rawResponse?: Response | undefined;

  /** The original data that was passed to this error instance. */
  data$: ClearPlaylistContentsUnauthorizedData;

  constructor(err: ClearPlaylistContentsUnauthorizedData) {
    const message = "message" in err && typeof err.message === "string"
      ? err.message
      : `API error occurred: ${JSON.stringify(err)}`;
    super(message);
    this.data$ = err;

    if (err.errors != null) this.errors = err.errors;
    if (err.rawResponse != null) this.rawResponse = err.rawResponse;

    this.name = "ClearPlaylistContentsUnauthorized";
  }
}

export type ClearPlaylistContentsErrors = {
  code?: number | undefined;
  message?: string | undefined;
  status?: number | undefined;
};

/**
 * Bad Request - A parameter was not specified, or was specified incorrectly.
 */
export type ClearPlaylistContentsBadRequestData = {
  errors?: Array<ClearPlaylistContentsErrors> | undefined;
  /**
   * Raw HTTP response; suitable for custom response parsing
   */
  rawResponse?: Response | undefined;
};

/**
 * Bad Request - A parameter was not specified, or was specified incorrectly.
 */
export class ClearPlaylistContentsBadRequest extends Error {
  errors?: Array<ClearPlaylistContentsErrors> | undefined;
  /**
   * Raw HTTP response; suitable for custom response parsing
   */
  rawResponse?: Response | undefined;

  /** The original data that was passed to this error instance. */
  data$: ClearPlaylistContentsBadRequestData;

  constructor(err: ClearPlaylistContentsBadRequestData) {
    const message = "message" in err && typeof err.message === "string"
      ? err.message
      : `API error occurred: ${JSON.stringify(err)}`;
    super(message);
    this.data$ = err;

    if (err.errors != null) this.errors = err.errors;
    if (err.rawResponse != null) this.rawResponse = err.rawResponse;

    this.name = "ClearPlaylistContentsBadRequest";
  }
}

/** @internal */
export const ClearPlaylistContentsPlaylistsErrors$inboundSchema: z.ZodType<
  ClearPlaylistContentsPlaylistsErrors,
  z.ZodTypeDef,
  unknown
> = z.object({
  code: z.number().int().optional(),
  message: z.string().optional(),
  status: z.number().int().optional(),
});

/** @internal */
export type ClearPlaylistContentsPlaylistsErrors$Outbound = {
  code?: number | undefined;
  message?: string | undefined;
  status?: number | undefined;
};

/** @internal */
export const ClearPlaylistContentsPlaylistsErrors$outboundSchema: z.ZodType<
  ClearPlaylistContentsPlaylistsErrors$Outbound,
  z.ZodTypeDef,
  ClearPlaylistContentsPlaylistsErrors
> = z.object({
  code: z.number().int().optional(),
  message: z.string().optional(),
  status: z.number().int().optional(),
});

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

export function clearPlaylistContentsPlaylistsErrorsToJSON(
  clearPlaylistContentsPlaylistsErrors: ClearPlaylistContentsPlaylistsErrors,
): string {
  return JSON.stringify(
    ClearPlaylistContentsPlaylistsErrors$outboundSchema.parse(
      clearPlaylistContentsPlaylistsErrors,
    ),
  );
}

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

/** @internal */
export const ClearPlaylistContentsUnauthorized$inboundSchema: z.ZodType<
  ClearPlaylistContentsUnauthorized,
  z.ZodTypeDef,
  unknown
> = z.object({
  errors: z.array(
    z.lazy(() => ClearPlaylistContentsPlaylistsErrors$inboundSchema),
  ).optional(),
  RawResponse: z.instanceof(Response).optional(),
})
  .transform((v) => {
    const remapped = remap$(v, {
      "RawResponse": "rawResponse",
    });

    return new ClearPlaylistContentsUnauthorized(remapped);
  });

/** @internal */
export type ClearPlaylistContentsUnauthorized$Outbound = {
  errors?: Array<ClearPlaylistContentsPlaylistsErrors$Outbound> | undefined;
  RawResponse?: never | undefined;
};

/** @internal */
export const ClearPlaylistContentsUnauthorized$outboundSchema: z.ZodType<
  ClearPlaylistContentsUnauthorized$Outbound,
  z.ZodTypeDef,
  ClearPlaylistContentsUnauthorized
> = z.instanceof(ClearPlaylistContentsUnauthorized)
  .transform(v => v.data$)
  .pipe(
    z.object({
      errors: z.array(
        z.lazy(() => ClearPlaylistContentsPlaylistsErrors$outboundSchema),
      ).optional(),
      rawResponse: z.instanceof(Response).transform(() => {
        throw new Error("Response cannot be serialized");
      }).optional(),
    }).transform((v) => {
      return remap$(v, {
        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 ClearPlaylistContentsUnauthorized$ {
  /** @deprecated use `ClearPlaylistContentsUnauthorized$inboundSchema` instead. */
  export const inboundSchema = ClearPlaylistContentsUnauthorized$inboundSchema;
  /** @deprecated use `ClearPlaylistContentsUnauthorized$outboundSchema` instead. */
  export const outboundSchema =
    ClearPlaylistContentsUnauthorized$outboundSchema;
  /** @deprecated use `ClearPlaylistContentsUnauthorized$Outbound` instead. */
  export type Outbound = ClearPlaylistContentsUnauthorized$Outbound;
}

/** @internal */
export const ClearPlaylistContentsErrors$inboundSchema: z.ZodType<
  ClearPlaylistContentsErrors,
  z.ZodTypeDef,
  unknown
> = z.object({
  code: z.number().int().optional(),
  message: z.string().optional(),
  status: z.number().int().optional(),
});

/** @internal */
export type ClearPlaylistContentsErrors$Outbound = {
  code?: number | undefined;
  message?: string | undefined;
  status?: number | undefined;
};

/** @internal */
export const ClearPlaylistContentsErrors$outboundSchema: z.ZodType<
  ClearPlaylistContentsErrors$Outbound,
  z.ZodTypeDef,
  ClearPlaylistContentsErrors
> = z.object({
  code: z.number().int().optional(),
  message: z.string().optional(),
  status: z.number().int().optional(),
});

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

export function clearPlaylistContentsErrorsToJSON(
  clearPlaylistContentsErrors: ClearPlaylistContentsErrors,
): string {
  return JSON.stringify(
    ClearPlaylistContentsErrors$outboundSchema.parse(
      clearPlaylistContentsErrors,
    ),
  );
}

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

/** @internal */
export const ClearPlaylistContentsBadRequest$inboundSchema: z.ZodType<
  ClearPlaylistContentsBadRequest,
  z.ZodTypeDef,
  unknown
> = z.object({
  errors: z.array(z.lazy(() => ClearPlaylistContentsErrors$inboundSchema))
    .optional(),
  RawResponse: z.instanceof(Response).optional(),
})
  .transform((v) => {
    const remapped = remap$(v, {
      "RawResponse": "rawResponse",
    });

    return new ClearPlaylistContentsBadRequest(remapped);
  });

/** @internal */
export type ClearPlaylistContentsBadRequest$Outbound = {
  errors?: Array<ClearPlaylistContentsErrors$Outbound> | undefined;
  RawResponse?: never | undefined;
};

/** @internal */
export const ClearPlaylistContentsBadRequest$outboundSchema: z.ZodType<
  ClearPlaylistContentsBadRequest$Outbound,
  z.ZodTypeDef,
  ClearPlaylistContentsBadRequest
> = z.instanceof(ClearPlaylistContentsBadRequest)
  .transform(v => v.data$)
  .pipe(
    z.object({
      errors: z.array(z.lazy(() => ClearPlaylistContentsErrors$outboundSchema))
        .optional(),
      rawResponse: z.instanceof(Response).transform(() => {
        throw new Error("Response cannot be serialized");
      }).optional(),
    }).transform((v) => {
      return remap$(v, {
        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 ClearPlaylistContentsBadRequest$ {
  /** @deprecated use `ClearPlaylistContentsBadRequest$inboundSchema` instead. */
  export const inboundSchema = ClearPlaylistContentsBadRequest$inboundSchema;
  /** @deprecated use `ClearPlaylistContentsBadRequest$outboundSchema` instead. */
  export const outboundSchema = ClearPlaylistContentsBadRequest$outboundSchema;
  /** @deprecated use `ClearPlaylistContentsBadRequest$Outbound` instead. */
  export type Outbound = ClearPlaylistContentsBadRequest$Outbound;
}
