/*
 * 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 GetWatchListWatchlistErrors = {
  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 GetWatchListUnauthorizedData = {
  errors?: Array<GetWatchListWatchlistErrors> | 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 GetWatchListUnauthorized extends Error {
  errors?: Array<GetWatchListWatchlistErrors> | undefined;
  /**
   * Raw HTTP response; suitable for custom response parsing
   */
  rawResponse?: Response | undefined;

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

  constructor(err: GetWatchListUnauthorizedData) {
    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 = "GetWatchListUnauthorized";
  }
}

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

/**
 * Bad Request - A parameter was not specified, or was specified incorrectly.
 */
export type GetWatchListBadRequestData = {
  errors?: Array<GetWatchListErrors> | 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 GetWatchListBadRequest extends Error {
  errors?: Array<GetWatchListErrors> | undefined;
  /**
   * Raw HTTP response; suitable for custom response parsing
   */
  rawResponse?: Response | undefined;

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

  constructor(err: GetWatchListBadRequestData) {
    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 = "GetWatchListBadRequest";
  }
}

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

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

/** @internal */
export const GetWatchListWatchlistErrors$outboundSchema: z.ZodType<
  GetWatchListWatchlistErrors$Outbound,
  z.ZodTypeDef,
  GetWatchListWatchlistErrors
> = 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 GetWatchListWatchlistErrors$ {
  /** @deprecated use `GetWatchListWatchlistErrors$inboundSchema` instead. */
  export const inboundSchema = GetWatchListWatchlistErrors$inboundSchema;
  /** @deprecated use `GetWatchListWatchlistErrors$outboundSchema` instead. */
  export const outboundSchema = GetWatchListWatchlistErrors$outboundSchema;
  /** @deprecated use `GetWatchListWatchlistErrors$Outbound` instead. */
  export type Outbound = GetWatchListWatchlistErrors$Outbound;
}

export function getWatchListWatchlistErrorsToJSON(
  getWatchListWatchlistErrors: GetWatchListWatchlistErrors,
): string {
  return JSON.stringify(
    GetWatchListWatchlistErrors$outboundSchema.parse(
      getWatchListWatchlistErrors,
    ),
  );
}

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

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

    return new GetWatchListUnauthorized(remapped);
  });

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

/** @internal */
export const GetWatchListUnauthorized$outboundSchema: z.ZodType<
  GetWatchListUnauthorized$Outbound,
  z.ZodTypeDef,
  GetWatchListUnauthorized
> = z.instanceof(GetWatchListUnauthorized)
  .transform(v => v.data$)
  .pipe(
    z.object({
      errors: z.array(z.lazy(() => GetWatchListWatchlistErrors$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 GetWatchListUnauthorized$ {
  /** @deprecated use `GetWatchListUnauthorized$inboundSchema` instead. */
  export const inboundSchema = GetWatchListUnauthorized$inboundSchema;
  /** @deprecated use `GetWatchListUnauthorized$outboundSchema` instead. */
  export const outboundSchema = GetWatchListUnauthorized$outboundSchema;
  /** @deprecated use `GetWatchListUnauthorized$Outbound` instead. */
  export type Outbound = GetWatchListUnauthorized$Outbound;
}

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

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

/** @internal */
export const GetWatchListErrors$outboundSchema: z.ZodType<
  GetWatchListErrors$Outbound,
  z.ZodTypeDef,
  GetWatchListErrors
> = 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 GetWatchListErrors$ {
  /** @deprecated use `GetWatchListErrors$inboundSchema` instead. */
  export const inboundSchema = GetWatchListErrors$inboundSchema;
  /** @deprecated use `GetWatchListErrors$outboundSchema` instead. */
  export const outboundSchema = GetWatchListErrors$outboundSchema;
  /** @deprecated use `GetWatchListErrors$Outbound` instead. */
  export type Outbound = GetWatchListErrors$Outbound;
}

export function getWatchListErrorsToJSON(
  getWatchListErrors: GetWatchListErrors,
): string {
  return JSON.stringify(
    GetWatchListErrors$outboundSchema.parse(getWatchListErrors),
  );
}

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

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

    return new GetWatchListBadRequest(remapped);
  });

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

/** @internal */
export const GetWatchListBadRequest$outboundSchema: z.ZodType<
  GetWatchListBadRequest$Outbound,
  z.ZodTypeDef,
  GetWatchListBadRequest
> = z.instanceof(GetWatchListBadRequest)
  .transform(v => v.data$)
  .pipe(
    z.object({
      errors: z.array(z.lazy(() => GetWatchListErrors$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 GetWatchListBadRequest$ {
  /** @deprecated use `GetWatchListBadRequest$inboundSchema` instead. */
  export const inboundSchema = GetWatchListBadRequest$inboundSchema;
  /** @deprecated use `GetWatchListBadRequest$outboundSchema` instead. */
  export const outboundSchema = GetWatchListBadRequest$outboundSchema;
  /** @deprecated use `GetWatchListBadRequest$Outbound` instead. */
  export type Outbound = GetWatchListBadRequest$Outbound;
}
