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

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

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

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

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

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

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

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

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

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

export function getSessionHistorySessionsErrorsToJSON(
  getSessionHistorySessionsErrors: GetSessionHistorySessionsErrors,
): string {
  return JSON.stringify(
    GetSessionHistorySessionsErrors$outboundSchema.parse(
      getSessionHistorySessionsErrors,
    ),
  );
}

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

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

    return new GetSessionHistoryUnauthorized(remapped);
  });

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

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

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

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

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

export function getSessionHistoryErrorsToJSON(
  getSessionHistoryErrors: GetSessionHistoryErrors,
): string {
  return JSON.stringify(
    GetSessionHistoryErrors$outboundSchema.parse(getSessionHistoryErrors),
  );
}

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

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

    return new GetSessionHistoryBadRequest(remapped);
  });

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

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