// Messages between the elements and their workers. Extends the site's gang sheet protocol
// (lib/gangsheet/protocol.ts) with fixed-sheet packing and a start-up "ready" message.

import type { FixedSheetOption, FixedSheetPlan } from "../../engine/fixed-sheets";
import type { StripPackInput } from "../../engine/strip";
import type { GangsheetRequest, GangsheetResponse } from "../../../lib/gangsheet/protocol";
import type { QuantitiesConfig } from "./config";
import type { QuantitiesCoreMessages } from "./i18n/quantities/core-en";
import type { QuantityInputs, QuantityResult } from "./quantities-core";

export type EmbedSheetRequest =
  | GangsheetRequest
  // cutMarginMm: a sticker sheet; spacing and edge margin are raised to the sticker sheet minimums.
  | { type: "pack-sheets"; requestId: number; input: StripPackInput; options: FixedSheetOption[]; cutMarginMm?: number };

export type EmbedSheetResponse =
  | GangsheetResponse
  | { type: "packed-sheets"; requestId: number; plan: FixedSheetPlan }
  | { type: "ready"; requestId: 0 };

// `lang` and `messages`: the shopper's language and its result words (src/i18n/quantities/core-*.ts).
// Left out for English, which the worker has built in.
export type QuantityRequest = {
  type: "quantity";
  requestId: number;
  config: QuantitiesConfig;
  inputs: QuantityInputs;
  lang?: string;
  messages?: QuantitiesCoreMessages;
};

export type QuantityResponse =
  | { type: "quantity"; requestId: number; result: QuantityResult }
  | { type: "error"; requestId: number; message: string }
  | { type: "ready"; requestId: 0 };
