/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 */

import * as z from "zod";
import { remap as remap$ } from "../../../lib/primitives.js";

export type UpdatePlayProgressMediaErrors = {
  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 UpdatePlayProgressUnauthorizedData = {
  errors?: Array<UpdatePlayProgressMediaErrors> | 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 UpdatePlayProgressUnauthorized extends Error {
  errors?: Array<UpdatePlayProgressMediaErrors> | undefined;
  /**
   * Raw HTTP response; suitable for custom response parsing
   */
  rawResponse?: Response | undefined;

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

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

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

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

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

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

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

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

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

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

    return new UpdatePlayProgressUnauthorized(remapped);
  });

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

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

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

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

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

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

    return new UpdatePlayProgressBadRequest(remapped);
  });

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

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