import { z } from "@homarr/validation";

export const queueSchema = z.object({
  queue: z.object({
    status: z.string(),
    speedlimit: z.string(),
    speedlimit_abs: z.string(),
    paused: z.boolean(),
    noofslots_total: z.number(),
    noofslots: z.number(),
    limit: z.number(),
    start: z.number(),
    timeleft: z.string(),
    speed: z.string(),
    kbpersec: z.string(),
    size: z.string(),
    sizeleft: z.string(),
    mb: z.string(),
    mbleft: z.string(),
    slots: z.array(
      z.object({
        status: z.string(),
        index: z.number(),
        password: z.string(),
        avg_age: z.string(),
        script: z.string(),
        has_rating: z.boolean().optional(),
        mb: z.string(),
        mbleft: z.string(),
        mbmissing: z.string(),
        size: z.string(),
        sizeleft: z.string(),
        filename: z.string(),
        labels: z.array(z.string().or(z.null())).or(z.null()).optional(),
        priority: z
          .number()
          .or(z.string())
          .transform((priority) => (typeof priority === "number" ? priority : parseInt(priority))),
        cat: z.string(),
        timeleft: z.string(),
        percentage: z.string(),
        nzo_id: z.string(),
        unpackopts: z.string(),
      }),
    ),
    categories: z.array(z.string()).or(z.null()).optional(),
    scripts: z.array(z.string()).or(z.null()).optional(),
    diskspace1: z.string(),
    diskspace2: z.string(),
    diskspacetotal1: z.string(),
    diskspacetotal2: z.string(),
    diskspace1_norm: z.string(),
    diskspace2_norm: z.string(),
    have_warnings: z.string(),
    pause_int: z.string(),
    loadavg: z.string().optional(),
    left_quota: z.string(),
    version: z.string(),
    finish: z.number(),
    cache_art: z.string(),
    cache_size: z.string(),
    finishaction: z.null().optional(),
    paused_all: z.boolean(),
    quota: z.string(),
    have_quota: z.boolean(),
    queue_details: z.string().optional(),
  }),
});

export const historySchema = z.object({
  history: z.object({
    noofslots: z.number(),
    day_size: z.string(),
    week_size: z.string(),
    month_size: z.string(),
    total_size: z.string(),
    last_history_update: z.number(),
    slots: z.array(
      z.object({
        action_line: z.string(),
        series: z.string().or(z.null()).optional(),
        script_log: z.string().optional(),
        meta: z.null().optional(),
        fail_message: z.string(),
        loaded: z.boolean(),
        id: z.number().optional(),
        size: z.string(),
        category: z.string(),
        pp: z.string(),
        retry: z.number(),
        script: z.string(),
        nzb_name: z.string(),
        download_time: z.number(),
        storage: z.string(),
        has_rating: z.boolean().optional(),
        status: z.string(),
        script_line: z.string(),
        completed: z.number(),
        nzo_id: z.string(),
        downloaded: z.number(),
        report: z.string(),
        password: z.string().or(z.null()).optional(),
        path: z.string(),
        postproc_time: z.number(),
        name: z.string(),
        url: z.string().or(z.null()).optional(),
        md5sum: z.string(),
        bytes: z.number(),
        url_info: z.string(),
        stage_log: z
          .array(
            z.object({
              name: z.string(),
              actions: z.array(z.string()).or(z.null()).optional(),
            }),
          )
          .optional(),
      }),
    ),
  }),
});
