# Inventory Service

> Stock management for Retail and F&B ingredient tracking.

## Overview

Inventory Service manages "physical stock" for both finished goods (Retail) and raw ingredients (F&B). It supports different deduction logic based on product type.

### Key Features

- **Stock Tracking** - Real-time stock levels per shop
- **Reservation** - Reserve stock during order validation
- **Recipe Integration** - Deduct ingredients by recipe for F&B
- **Transactions** - Full audit trail (IN, OUT, ADJUSTMENT)
- **Alerts** - Low stock notifications

## Architecture Context

```mermaid
graph LR
    ORDER["📝 Order Service"] --> INVENTORY["🏭 Inventory Service"]
    FNB["🍳 F&B Engine"] --> INVENTORY
    POS["POS"] --> INVENTORY
    
    style INVENTORY fill:#27ae60,stroke:#1e8449,color:#fff
```

## Stock Deduction Logic

| Product Type | Logic | Example |
|--------------|-------|---------|
| Physical (Retail) | 1:1 | Sell 1 T-shirt → Deduct 1 |
| PreparedFood (F&B) | Recipe-based | Sell 1 Latte → Deduct 18g beans + 200ml milk |

## Quick Start

```bash
cd services/inventory-service-net
cp .env.example .env
dotnet run --project src/InventoryService.API
```

## API Endpoints

| Method | Endpoint | Description |
|--------|----------|-------------|
| `GET` | `/api/v1/inventory` | List inventory by shop |
| `GET` | `/api/v1/inventory/{productId}` | Get stock level |
| `POST` | `/api/v1/inventory/stock-in` | Add stock |
| `POST` | `/api/v1/inventory/stock-out` | Remove stock |
| `POST` | `/api/v1/inventory/reserve` | Reserve for order |
| `POST` | `/api/v1/inventory/release` | Release reservation |
| `POST` | `/api/v1/inventory/adjust` | Stock adjustment |
| `GET` | `/api/v1/inventory/transactions` | Transaction history |

## Domain Model

```csharp
public class InventoryItem : Entity, IAggregateRoot
{
    public Guid ProductId { get; private set; }
    public Guid ShopId { get; private set; }
    public int Quantity { get; private set; }
    public int ReservedQuantity { get; private set; }
    public int AvailableQuantity => Quantity - ReservedQuantity;
    
    public void StockIn(int amount, string reference);
    public void StockOut(int amount, string reference);
    public void Reserve(int amount, Guid orderId);
    public void ReleaseReservation(Guid orderId);
}
```

## Related Services

- [Order Service](../../order-service-net/docs/en/README.md) - Consumes via RetailStrategy
- [Catalog Service](../../catalog-service-net/docs/en/README.md) - Product reference
- [F&B Engine](../../fnb-engine-net/docs/en/README.md) - Recipe-based deduction

## License

Proprietary - GoodGo Platform
