from typing import List

from pydantic import BaseModel, Field
import uuid
import datetime

{% for model in models %}
class {{ model.base_schema_name }}(BaseModel):
    """pk"""
    {% for field_name, field in model.pk.items() %}{{field_name}}: {{field.python_type_str}} = Field(
        {%- if field.default_str %}default={{field.default_str}},{%- endif -%}
        {%- if field.default_factory_str %}default_factory={{field.default_factory_str}},{%- endif -%}
    )
    {% endfor %}
    """fields"""
    {% for field_name, field in model.fields.items() %}{{field_name}}: {{field.python_type_str}} = Field(
        {%- if field.default_str %}default={{field.default_str}},{%- endif -%}
        {%- if field.default_factory_str %}default_factory={{field.default_factory_str}},{%- endif -%}
    )
    {% endfor %}
    class Config:
        from_attributes = True

{% for combination in model.relationship_combinations %}
class {{ model.base_schema_name }}With{{ combination.name }}({{ model.base_schema_name }}):
    {%- for relation in combination.combination -%}
    {% if relation.side == 'one' %}
    {{ relation.target.snake_name }}: "{{ relation.target.base_schema_name }}" = Field(alias="relation_one_{{ relation.target.snake_name }}")
    {% else %}
    {{ relation.target.snake_plural_name }}: List["{{ relation.target.base_schema_name }}"] = Field(alias="relation_many_{{ relation.target.snake_name }}")
    {%- endif -%}
    {% endfor %}
{% endfor -%}
{%- endfor -%}

{%- for model in models -%}
{% for combination in model.relationship_combinations %}
{{ model.base_schema_name }}With{{ combination.name }}.model_rebuild()
{%- endfor -%}
{% endfor %}

