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

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

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

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

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

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

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

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

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

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

export function markPlayedMediaErrorsToJSON(
  markPlayedMediaErrors: MarkPlayedMediaErrors,
): string {
  return JSON.stringify(
    MarkPlayedMediaErrors$outboundSchema.parse(markPlayedMediaErrors),
  );
}

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

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

    return new MarkPlayedUnauthorized(remapped);
  });

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

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

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

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

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

export function markPlayedErrorsToJSON(
  markPlayedErrors: MarkPlayedErrors,
): string {
  return JSON.stringify(
    MarkPlayedErrors$outboundSchema.parse(markPlayedErrors),
  );
}

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

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

    return new MarkPlayedBadRequest(remapped);
  });

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

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