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

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

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

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

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

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

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

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

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

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

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

    return new StartTaskUnauthorized(remapped);
  });

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

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

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

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

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

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

    return new StartTaskBadRequest(remapped);
  });

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

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