export type Tag = {
  id: number;
  name: string;
};

export type ProductTag = {
  productId: number;
  tagId: number;
  tag: Tag;
};

export type Nutrition = {
  id: number;
  productId: number;
  calories: number | null;
  protein: number | null;
  fat: number | null;
  carbohydrates: number | null;
  salt: number | null;
  sugar: number | null;
  fiber: number | null;
};

export type Category = {
  id: number;
  name: string;
  parentId: number | null;
  parent: Category | null;
};

export type Product = {
  id: number;
  name: string;
  normalizedName: string;
  category: string | null;
  subcategory: string | null;
  brand: string | null;
  canonicalName: string | null;
  isActive: boolean;
  deletedAt: string | null;
  createdAt: string;
  updatedAt: string;
  tags?: ProductTag[];
  nutrition?: Nutrition | null;
  categoryId?: number | null;
  categoryRef?: Category | null;
};

export type InventoryItem = {
  id: number;
  productId: number;
  quantity: string;
  unit: string;
  location: string | null;
  purchaseDate: string | null;
  opened: boolean | null;
  suitableFor: string | null;
  bestBeforeDate: string | null;
  brand: string | null;
  comment: string | null;
  createdAt: string;
  updatedAt: string;
  product: Product;
};

export type MergePreviewProduct = Product & {
  inventoryCount: number;
};

export type MergePreview = {
  source: MergePreviewProduct;
  target: MergePreviewProduct;
  outcome: {
    inventoryItemsToMove: number;
    sourceWillBeSoftDeleted: boolean;
    targetWillRemainActive: boolean;
  };
};

export type InventoryConsumption = {
  id: number;
  inventoryItemId: number;
  amountUsed: string;
  comment: string | null;
  createdAt: string;
  inventoryItem?: { unit: string };
};
export type RecipeIngredient = {
  id: number;
  recipeId: number;
  productId: number;
  quantity: string;
  unit: string;
  note: string | null;
  createdAt: string;
  updatedAt: string;
  product: Product;
};

export type Recipe = {
  id: number;
  name: string;
  description: string | null;
  instructions: string | null;
  imageUrl: string | null;
  servings: number | null;
  isPublic: boolean;
  ownerId: number | null;
  owner: { id: number; username: string } | null;
  shares: { userId: number }[];
  createdAt: string;
  updatedAt: string;
  ingredients: RecipeIngredient[];
};

export type RecipePreviewInventoryItem = {
  id: number;
  quantity: string;
  unit: string;
};

export type RecipePreviewMatchingInventoryItem = RecipePreviewInventoryItem & {
  brand: string | null;
  location: string | null;
  bestBeforeDate: string | null;
};

export type RecipePreviewOtherInventoryItem = RecipePreviewInventoryItem & {
  location: string | null;
  canConvert: boolean;
  convertedQuantity: number;
};

export type RecipeInventoryPreviewIngredient = {
  ingredientId: number;
  productId: number;
  productName: string;
  requiredQuantity: number;
  requiredUnit: string;
  note: string | null;
  availableQuantity: number;
  availableUnit: string | null;
  matchingInventoryItems: RecipePreviewMatchingInventoryItem[];
  otherInventoryItems: RecipePreviewOtherInventoryItem[];
  status: 'enough' | 'missing' | 'unit_mismatch';
  missingQuantity: number;
};

export type RecipeInventoryPreview = {
  recipe: {
    id: number;
    name: string;
    description: string | null;
  };
  ingredients: RecipeInventoryPreviewIngredient[];
  summary: {
    totalIngredients: number;
    enoughCount: number;
    missingCount: number;
    unitMismatchCount: number;
    canCookExactly: boolean;
  };
};