/*
 * 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 "../errors/sdkvalidationerror.js";

/**
 * the name of the task to be started.
 */
export enum TaskName {
  BackupDatabase = "BackupDatabase",
  BuildGracenoteCollections = "BuildGracenoteCollections",
  CheckForUpdates = "CheckForUpdates",
  CleanOldBundles = "CleanOldBundles",
  CleanOldCacheFiles = "CleanOldCacheFiles",
  DeepMediaAnalysis = "DeepMediaAnalysis",
  GenerateAutoTags = "GenerateAutoTags",
  GenerateChapterThumbs = "GenerateChapterThumbs",
  GenerateMediaIndexFiles = "GenerateMediaIndexFiles",
  OptimizeDatabase = "OptimizeDatabase",
  RefreshLibraries = "RefreshLibraries",
  RefreshLocalMedia = "RefreshLocalMedia",
  RefreshPeriodicMetadata = "RefreshPeriodicMetadata",
  UpgradeMediaAnalysis = "UpgradeMediaAnalysis",
}

export type StartTaskRequest = {
  /**
   * the name of the task to be started.
   */
  taskName: TaskName;
};

export type StartTaskResponse = {
  /**
   * HTTP response content type for this operation
   */
  contentType: string;
  /**
   * HTTP response status code for this operation
   */
  statusCode: number;
  /**
   * Raw HTTP response; suitable for custom response parsing
   */
  rawResponse: Response;
};

/** @internal */
export const TaskName$inboundSchema: z.ZodNativeEnum<typeof TaskName> = z
  .nativeEnum(TaskName);

/** @internal */
export const TaskName$outboundSchema: z.ZodNativeEnum<typeof TaskName> =
  TaskName$inboundSchema;

/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export namespace TaskName$ {
  /** @deprecated use `TaskName$inboundSchema` instead. */
  export const inboundSchema = TaskName$inboundSchema;
  /** @deprecated use `TaskName$outboundSchema` instead. */
  export const outboundSchema = TaskName$outboundSchema;
}

/** @internal */
export const StartTaskRequest$inboundSchema: z.ZodType<
  StartTaskRequest,
  z.ZodTypeDef,
  unknown
> = z.object({
  taskName: TaskName$inboundSchema,
});

/** @internal */
export type StartTaskRequest$Outbound = {
  taskName: string;
};

/** @internal */
export const StartTaskRequest$outboundSchema: z.ZodType<
  StartTaskRequest$Outbound,
  z.ZodTypeDef,
  StartTaskRequest
> = z.object({
  taskName: TaskName$outboundSchema,
});

/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export namespace StartTaskRequest$ {
  /** @deprecated use `StartTaskRequest$inboundSchema` instead. */
  export const inboundSchema = StartTaskRequest$inboundSchema;
  /** @deprecated use `StartTaskRequest$outboundSchema` instead. */
  export const outboundSchema = StartTaskRequest$outboundSchema;
  /** @deprecated use `StartTaskRequest$Outbound` instead. */
  export type Outbound = StartTaskRequest$Outbound;
}

export function startTaskRequestToJSON(
  startTaskRequest: StartTaskRequest,
): string {
  return JSON.stringify(
    StartTaskRequest$outboundSchema.parse(startTaskRequest),
  );
}

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

/** @internal */
export const StartTaskResponse$inboundSchema: z.ZodType<
  StartTaskResponse,
  z.ZodTypeDef,
  unknown
> = z.object({
  ContentType: z.string(),
  StatusCode: z.number().int(),
  RawResponse: z.instanceof(Response),
}).transform((v) => {
  return remap$(v, {
    "ContentType": "contentType",
    "StatusCode": "statusCode",
    "RawResponse": "rawResponse",
  });
});

/** @internal */
export type StartTaskResponse$Outbound = {
  ContentType: string;
  StatusCode: number;
  RawResponse: never;
};

/** @internal */
export const StartTaskResponse$outboundSchema: z.ZodType<
  StartTaskResponse$Outbound,
  z.ZodTypeDef,
  StartTaskResponse
> = z.object({
  contentType: z.string(),
  statusCode: z.number().int(),
  rawResponse: z.instanceof(Response).transform(() => {
    throw new Error("Response cannot be serialized");
  }),
}).transform((v) => {
  return remap$(v, {
    contentType: "ContentType",
    statusCode: "StatusCode",
    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 StartTaskResponse$ {
  /** @deprecated use `StartTaskResponse$inboundSchema` instead. */
  export const inboundSchema = StartTaskResponse$inboundSchema;
  /** @deprecated use `StartTaskResponse$outboundSchema` instead. */
  export const outboundSchema = StartTaskResponse$outboundSchema;
  /** @deprecated use `StartTaskResponse$Outbound` instead. */
  export type Outbound = StartTaskResponse$Outbound;
}

export function startTaskResponseToJSON(
  startTaskResponse: StartTaskResponse,
): string {
  return JSON.stringify(
    StartTaskResponse$outboundSchema.parse(startTaskResponse),
  );
}

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