"""Item model for Work Statistics System.""" from datetime import datetime, timezone from app import db class Item(db.Model): """Item model representing a work item with unit price. Attributes: id: Primary key, auto-incremented name: Item's name (required, non-empty) unit_price: Price per unit (required, positive float) created_at: Timestamp when the record was created updated_at: Timestamp when the record was last updated """ __tablename__ = 'items' id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(100), nullable=False, index=True) unit_price = db.Column(db.Float, nullable=False) created_at = db.Column(db.DateTime, default=lambda: datetime.now(timezone.utc)) updated_at = db.Column(db.DateTime, default=lambda: datetime.now(timezone.utc), onupdate=lambda: datetime.now(timezone.utc)) def to_dict(self): """Convert model to dictionary for JSON serialization. Returns: Dictionary representation of the item """ return { 'id': self.id, 'name': self.name, 'unit_price': self.unit_price, 'created_at': self.created_at.isoformat() if self.created_at else None, 'updated_at': self.updated_at.isoformat() if self.updated_at else None } def __repr__(self): return f''