"""Microservice models for {{ module_name }} domain - lightweight and focused."""

from datetime import datetime
from sqlalchemy import Column, DateTime, Integer, String, Text, Boolean, Index
from sqlalchemy.sql import func

from config.database import Base


class {{ module_name_title }}(Base):
    """{{ module_name_title }} model optimized for microservice architecture.
    
    This model is designed to be lightweight and focused, containing only
    essential fields for microservice operations.
    """
    
    __tablename__ = "{{ module_name }}s"
    
    id = Column(Integer, primary_key=True, index=True, doc="Unique identifier")
    name = Column(String(100), nullable=False, index=True, doc="Display name")
    description = Column(Text, nullable=True, doc="Brief description")
    
    # Minimal status field
    is_active = Column(Boolean, default=True, index=True, doc="Active status")
    
    # Essential timestamps
    created_at = Column(DateTime(timezone=True), server_default=func.now(), index=True, doc="Creation time")
    updated_at = Column(DateTime(timezone=True), onupdate=func.now(), doc="Last update time")
    
    # Performance optimization
    __table_args__ = (
        Index('idx_{{ module_name }}_active_created', 'is_active', 'created_at'),
    )
    
    def __repr__(self):
        return f"<{{ module_name_title }}(id={self.id}, name='{self.name}')>"
    
    def to_dict(self):
        """Convert to dictionary for API responses."""
        return {
            'id': self.id,
            'name': self.name,
            'description': self.description,
            'is_active': self.is_active,
            'created_at': self.created_at.isoformat() if self.created_at else None,
            'updated_at': self.updated_at.isoformat() if self.updated_at else None,
        }
