import type { EntityManager } from '@mikro-orm/core';
import { Food } from '../modules/foods/entities/food.entity';
import { Inventory } from '../modules/inventory/entities/inventory.entity';

export class InventorySeeder {
  async run(em: EntityManager): Promise<void> {
    const foods = await em.find(Food, {});

    for (const food of foods) {
      // Check if inventory already exists for this food
      const existingInventory = await em.findOne(Inventory, {
        food: { id: food.id },
      });

      if (!existingInventory) {
        const inventory = em.create(Inventory, {
          food,
          totalStock: 50,
          availableStock: 50,
        });

        em.persist(inventory);
      }
    }

    await em.flush();
  }
}

