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

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

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

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

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

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

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

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

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

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

export function updatePlaylistPlaylistsErrorsToJSON(
  updatePlaylistPlaylistsErrors: UpdatePlaylistPlaylistsErrors,
): string {
  return JSON.stringify(
    UpdatePlaylistPlaylistsErrors$outboundSchema.parse(
      updatePlaylistPlaylistsErrors,
    ),
  );
}

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

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

    return new UpdatePlaylistUnauthorized(remapped);
  });

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

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

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

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

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

export function updatePlaylistErrorsToJSON(
  updatePlaylistErrors: UpdatePlaylistErrors,
): string {
  return JSON.stringify(
    UpdatePlaylistErrors$outboundSchema.parse(updatePlaylistErrors),
  );
}

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

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

    return new UpdatePlaylistBadRequest(remapped);
  });

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

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