/** Local model events — TUI/webview subscription for progress/status updates */

import { BusEvent } from "@/bus/bus-event"
import { Schema } from "effect"

export const LocalModelEvent = {
  DownloadStarted: BusEvent.define(
    "local.download.started",
    Schema.Struct({
      id: Schema.String,
      repo: Schema.String,
      filename: Schema.String,
      totalBytes: Schema.Number,
    }),
  ),
  DownloadProgress: BusEvent.define(
    "local.download.progress",
    Schema.Struct({
      id: Schema.String,
      downloaded: Schema.Number,
      total: Schema.Number,
      speedMBps: Schema.Finite,
    }),
  ),
  DownloadCompleted: BusEvent.define(
    "local.download.completed",
    Schema.Struct({
      id: Schema.String,
      repo: Schema.String,
      filename: Schema.String,
      path: Schema.String,
    }),
  ),
  DownloadFailed: BusEvent.define(
    "local.download.failed",
    Schema.Struct({
      id: Schema.String,
      repo: Schema.String,
      error: Schema.String,
    }),
  ),
  ModelStarted: BusEvent.define(
    "local.model.started",
    Schema.Struct({
      id: Schema.String,
      repo: Schema.String,
      endpoint: Schema.String,
      gpuIndex: Schema.optional(Schema.Number),
    }),
  ),
  ModelStopped: BusEvent.define(
    "local.model.stopped",
    Schema.Struct({
      id: Schema.String,
      repo: Schema.String,
    }),
  ),
  ModelError: BusEvent.define(
    "local.model.error",
    Schema.Struct({
      id: Schema.String,
      repo: Schema.String,
      error: Schema.String,
    }),
  ),
  GPUProfiled: BusEvent.define(
    "local.gpu.profiled",
    Schema.Struct({
      gpuCount: Schema.Number,
      totalVRAMMB: Schema.Number,
      availableVRAMMB: Schema.Number,
    }),
  ),
}
