from typing import Optional
from sqlalchemy.orm import Session
from atams.db import BaseRepository

from app.models.{{ singular_name }} import {{ pascal_name }}


class {{ pascal_name }}Repository(BaseRepository[{{ pascal_name }}]):
    """Repository for {{ pascal_name }} operations"""

    def __init__(self):
        super().__init__({{ pascal_name }})

    def get_by_name(self, db: Session, name: str) -> Optional[{{ pascal_name }}]:
        """Get {{ singular_name }} by name"""
        return db.query({{ pascal_name }}).filter({{ pascal_name }}.{{ prefix }}name == name).first()

    # TODO: Add custom query methods here
    # Example:
    # def get_active_{{ plural_name }}(self, db: Session) -> List[{{ pascal_name }}]:
    #     query = '''
    #         SELECT * FROM {{ db_schema }}.{{ table_name }}
    #         WHERE {{ prefix }}status = :status
    #     '''
    #     return self.execute_raw_sql_dict(db, query, {"status": "active"})
