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

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

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

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

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

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

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

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

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

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

export function stopTaskButlerErrorsToJSON(
  stopTaskButlerErrors: StopTaskButlerErrors,
): string {
  return JSON.stringify(
    StopTaskButlerErrors$outboundSchema.parse(stopTaskButlerErrors),
  );
}

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

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

    return new StopTaskUnauthorized(remapped);
  });

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

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

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

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

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

export function stopTaskErrorsToJSON(stopTaskErrors: StopTaskErrors): string {
  return JSON.stringify(StopTaskErrors$outboundSchema.parse(stopTaskErrors));
}

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

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

    return new StopTaskBadRequest(remapped);
  });

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

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