import type { StepTechStepView } from "./recipe.js";
import type { IngredientView, UnitView } from "./reference.js";

/**
 * One item from a source's own catalog (`RecipeSourceAdapter.list()`),
 * browsable regardless of whether it's already been imported —
 * `GET /sources/:sourceKey/browse`. Mirrors `BrowsableRecipeItem`
 * (apps/api's `recipe-source-adapter.ts`), plus `recipeId`: the already-
 * imported `Recipe`'s id when `alreadyImported` is true, so a caller (the
 * browse UI) can navigate straight to it without a second lookup — `null`
 * otherwise.
 */
export interface BrowsableSourceItemView {
  externalId: string;
  title: string;
  picture: string | null;
  url: string;
  alreadyImported: boolean;
  recipeId: number | null;
}

/**
 * One ingredient line of an unsaved import draft (`RecipeImportDraftView`)
 * — same spirit as `RecipeIngredientView`, but `ingredient`/`unit` can be
 * `null` (nothing in the catalog matched — see `ingredient-matcher.ts`) and
 * `quantity` can be missing entirely, since this hasn't been reviewed/fixed
 * up by a person yet.
 */
export interface DraftRecipeIngredientView {
  /** Exactly what the source wrote for this line — kept even once ingredient/unit resolve, so a review screen can show what the match was made from. */
  rawText: string;
  quantity: number | null;
  ingredient: IngredientView | null;
  unit: UnitView | null;
}

/** One step of an unsaved import draft — `techSteps` is detected the same way a real save computes it (`matchTechStepSpans`), just not persisted yet. */
export interface DraftRecipeStepView {
  description: string;
  picture: string | null;
  techSteps: StepTechStepView[];
}

/**
 * An unsaved preview of one source item, fully translated (ingredients/
 * units/techniques resolved against our catalogs where possible) —
 * `GET /sources/:sourceKey/preview/:externalId`. What a future import
 * review screen pre-fills its form from. Deliberately distinct from
 * `RecipeView`: nothing here has an id (nothing is saved), and ingredient/
 * unit resolution can be incomplete — nothing about this type assumes it's
 * ready to persist as-is.
 */
export interface RecipeImportDraftView {
  sourceKey: string;
  externalId: string;
  name: string;
  description: string | null;
  picture: string | null;
  portions: number | null;
  sourceUrl: string;
  ingredients: DraftRecipeIngredientView[];
  steps: DraftRecipeStepView[];
}
