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

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

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

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

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

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

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

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

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

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

export function cancelServerActivitiesActivitiesErrorsToJSON(
  cancelServerActivitiesActivitiesErrors:
    CancelServerActivitiesActivitiesErrors,
): string {
  return JSON.stringify(
    CancelServerActivitiesActivitiesErrors$outboundSchema.parse(
      cancelServerActivitiesActivitiesErrors,
    ),
  );
}

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

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

    return new CancelServerActivitiesUnauthorized(remapped);
  });

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

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

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

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

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

export function cancelServerActivitiesErrorsToJSON(
  cancelServerActivitiesErrors: CancelServerActivitiesErrors,
): string {
  return JSON.stringify(
    CancelServerActivitiesErrors$outboundSchema.parse(
      cancelServerActivitiesErrors,
    ),
  );
}

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

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

    return new CancelServerActivitiesBadRequest(remapped);
  });

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

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