{% if FILE.EXTRAS.HAS_CHILDREN is true %}
from sqlalchemy import ForeignKey
from sqlalchemy.orm import relationship
{% endif %}
from sqlalchemy import Column, Integer, String, DateTime
from pydantic import BaseModel
from typing import List, Optional
from datetime import datetime

# SQLAlchemy model for {{ MOD.NAME }}
class {{ MOD.NAME }}Model(Base):
    __tablename__ = "{{ MOD.NAME | plural | lower }}"
    id = Column(String, primary_key=True, default=generate_uuid, unique=True, index=True)
    date_created = Column(DateTime(timezone=True), default=datetime.utcnow)
    last_modified = Column(
        DateTime(timezone=True), default=datetime.utcnow, onupdate=datetime.utcnow
    )
    {{ MOD.EXTRAS.FIELD_DEFINITIONS }}
    {% if MOD.EXTRAS.HAS_CHILDREN is true %}
    children = relationship("{{ MOD.EXTRAS.CHILD_NAME }}", back_populates="parent")
    {% else %}
    # No relationships required.
    {% endif %}

# Pydantic schemas
class {{ MOD.NAME }}Update(BaseModel):
    # Fields that can be updated on {{ MOD.NAME }}
    ...

class {{ MOD.NAME }}Create({{ MOD.NAME }}Update):
    # Fields required for creating a {{ MOD.NAME }}
    ...

class {{ MOD.NAME }}({{ MOD.NAME }}Create):
    id: int
    # Other {{ MOD.NAME }} fields
    {% if MOD.EXTRAS.HAS_CHILDREN is true %}
    children: List[ChildRead] = []
    {% endif %}
    class Config:
        orm_mode = True

{% if MOD.EXTRAS.HAS_CHILDREN is true %}
class ChildRead(BaseModel):
    # Fields for nested child resource
    ...
    class Config:
        from_attributes  = True
{% endif %}



{% elif '_router.py' in FILE_NAME %}
from fastapi import APIRouter

from app.api.v1.utils import (
    create_route_objects,
    create_routers,
    attach_list_of_routers,
)



def get_routes(component_list):
    """
    Generate and return a list of routers for the application.

    This function creates route objects from the COMPONENTS, then uses these
    route objects to create routers of type SQLALCHEMY. Custom routes can be
    added by extending the routers list with additional route objects.

    Returns:
        list: A list of router objects.
    """
    routes = APIRouter()

    routes_to_create = create_route_objects(component_list)
    list_of_routers = create_routers(routes_to_create)
    attach_list_of_routers(routes, list_of_routers)

    return routes


router = get_routes([ {{ RESOURCE_NAME }}] )

