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

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

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

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

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

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

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

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

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

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

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

    return new StartAllTasksUnauthorized(remapped);
  });

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

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

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

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

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

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

    return new StartAllTasksBadRequest(remapped);
  });

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

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