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

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

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

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

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

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

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

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

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

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

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

    return new LogLineUnauthorized(remapped);
  });

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

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

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

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

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

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

    return new LogLineBadRequest(remapped);
  });

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

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