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

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

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

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

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

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

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

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

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

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

export function getFileHashLibraryErrorsToJSON(
  getFileHashLibraryErrors: GetFileHashLibraryErrors,
): string {
  return JSON.stringify(
    GetFileHashLibraryErrors$outboundSchema.parse(getFileHashLibraryErrors),
  );
}

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

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

    return new GetFileHashUnauthorized(remapped);
  });

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

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

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

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

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

export function getFileHashErrorsToJSON(
  getFileHashErrors: GetFileHashErrors,
): string {
  return JSON.stringify(
    GetFileHashErrors$outboundSchema.parse(getFileHashErrors),
  );
}

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

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

    return new GetFileHashBadRequest(remapped);
  });

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

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