{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://schemas.bakery-ia.com/demo/inventory/stock/v1",
  "type": "object",
  "title": "Stock",
  "description": "Stock levels and batch tracking for demo cloning",
  "properties": {
    "id": {
      "type": "string",
      "format": "uuid",
      "description": "Unique stock identifier"
    },
    "tenant_id": {
      "type": "string",
      "format": "uuid",
      "description": "Tenant owner (replaced during cloning)"
    },
    "ingredient_id": {
      "type": "string",
      "format": "uuid",
      "description": "Reference to inventory.Ingredient"
    },
    "supplier_id": {
      "type": ["string", "null"],
      "format": "uuid",
      "description": "Cross-service ref to suppliers.Supplier"
    },
    "batch_number": {
      "type": ["string", "null"],
      "maxLength": 100
    },
    "lot_number": {
      "type": ["string", "null"],
      "maxLength": 100
    },
    "supplier_batch_ref": {
      "type": ["string", "null"],
      "maxLength": 100
    },
    "production_stage": {
      "type": "string",
      "enum": ["raw_ingredient", "par_baked", "fully_baked", "prepared_dough", "frozen_product"],
      "default": "raw_ingredient"
    },
    "transformation_reference": {
      "type": ["string", "null"],
      "maxLength": 100
    },
    "current_quantity": {
      "type": "number",
      "minimum": 0,
      "default": 0
    },
    "reserved_quantity": {
      "type": "number",
      "minimum": 0,
      "default": 0
    },
    "available_quantity": {
      "type": "number",
      "minimum": 0,
      "default": 0
    },
    "received_date": {
      "type": ["string", "null"],
      "format": "date-time"
    },
    "expiration_date": {
      "type": ["string", "null"],
      "format": "date-time"
    },
    "best_before_date": {
      "type": ["string", "null"],
      "format": "date-time"
    },
    "original_expiration_date": {
      "type": ["string", "null"],
      "format": "date-time"
    },
    "transformation_date": {
      "type": ["string", "null"],
      "format": "date-time"
    },
    "final_expiration_date": {
      "type": ["string", "null"],
      "format": "date-time"
    },
    "unit_cost": {
      "type": ["number", "null"],
      "minimum": 0
    },
    "total_cost": {
      "type": ["number", "null"],
      "minimum": 0
    },
    "storage_location": {
      "type": ["string", "null"],
      "maxLength": 100
    },
    "warehouse_zone": {
      "type": ["string", "null"],
      "maxLength": 50
    },
    "shelf_position": {
      "type": ["string", "null"],
      "maxLength": 50
    },
    "requires_refrigeration": {
      "type": "boolean",
      "default": false
    },
    "requires_freezing": {
      "type": "boolean",
      "default": false
    },
    "storage_temperature_min": {
      "type": ["number", "null"]
    },
    "storage_temperature_max": {
      "type": ["number", "null"]
    },
    "storage_humidity_max": {
      "type": ["number", "null"]
    },
    "shelf_life_days": {
      "type": ["integer", "null"],
      "minimum": 1
    },
    "storage_instructions": {
      "type": ["string", "null"]
    },
    "is_available": {
      "type": "boolean",
      "default": true
    },
    "is_expired": {
      "type": "boolean",
      "default": false
    },
    "quality_status": {
      "type": "string",
      "enum": ["good", "damaged", "expired", "quarantined"],
      "default": "good"
    },
    "created_at": {
      "type": ["string", "null"],
      "format": "date-time"
    },
    "updated_at": {
      "type": ["string", "null"],
      "format": "date-time"
    }
  },
  "required": [
    "id", "tenant_id", "ingredient_id", "current_quantity", "reserved_quantity", "available_quantity",
    "is_available", "is_expired", "quality_status"
  ],
  "additionalProperties": false
}