from sqlalchemy import Column, Integer, Numeric, ForeignKey, DateTime, Text
from sqlalchemy.orm import relationship
from datetime import datetime
from ...shared.config.database import Base

class InventoryTaskConsumption(Base):
    __tablename__ = 'inventory_task_consumptions'
    
    id = Column(Integer, primary_key=True, index=True, autoincrement=True)
    task_id = Column(Integer, ForeignKey('housekeeping_tasks.id'), nullable=False, index=True)
    item_id = Column(Integer, ForeignKey('inventory_items.id'), nullable=False, index=True)
    
    quantity = Column(Numeric(10, 2), nullable=False)
    notes = Column(Text, nullable=True)
    
    recorded_by = Column(Integer, ForeignKey('users.id'), nullable=True)
    recorded_at = Column(DateTime, nullable=False, default=datetime.utcnow, index=True)
    
    created_at = Column(DateTime, default=datetime.utcnow, nullable=False)
    
    # Relationships
    task = relationship('HousekeepingTask')
    item = relationship('InventoryItem', back_populates='task_consumptions')

