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

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

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

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

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

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

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

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

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

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

export function getResizedPhotoServerErrorsToJSON(
  getResizedPhotoServerErrors: GetResizedPhotoServerErrors,
): string {
  return JSON.stringify(
    GetResizedPhotoServerErrors$outboundSchema.parse(
      getResizedPhotoServerErrors,
    ),
  );
}

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

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

    return new GetResizedPhotoUnauthorized(remapped);
  });

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

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

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

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

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

export function getResizedPhotoErrorsToJSON(
  getResizedPhotoErrors: GetResizedPhotoErrors,
): string {
  return JSON.stringify(
    GetResizedPhotoErrors$outboundSchema.parse(getResizedPhotoErrors),
  );
}

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

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

    return new GetResizedPhotoBadRequest(remapped);
  });

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

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