# !!! DO NOT MODIFY !!!
# Automatically generated Model class
# Generated by "szndaogen" tool
{% if  viewStatementCreate -%}
"""
DATABASE VIEW Information:
-------------------------
{{ viewStatementCreate }}
"""
{%- endif %}

import typing
{%- for item in modelImports %}
import {{ item }}
{%- endfor %}
from szndaogen.data_access.model_base import ModelBase


class {{modelName}}Model(ModelBase):
    class Meta:
        TABLE_NAME: str = "{{ tableName }}"
        TABLE_TYPE: str = "{{ tableType }}"
        # fmt: off
        SQL_STATEMENT: str =
        {%-  if  viewStatement -%}
        {%-  for line in viewStatement.split("\n") %} {{ "                            " if not loop.first }}"""{{ line }} """{{ " \\\n" if not loop.last }}{%  endfor -%}
        {%- else %} "SELECT {PROJECTION} FROM `{{ tableName}}` {WHERE} {ORDER_BY} {LIMIT} {OFFSET}"
        {%- endif %}
        # fmt: on

        SQL_STATEMENT_WHERE_BASE: str = "{{ whereBase or 1 }}"
        SQL_STATEMENT_ORDER_BY_DEFAULT: str = "{{ orderByDefault or "" }}"

        PRIMARY_KEYS: typing.List = [{% for item in primaryKeys %}"{{ item }}", {% endfor %}]
        ATTRIBUTE_LIST: typing.List = [{% for attr in tableDescription %}"{{ attr['Field'] }}", {% endfor %}]
        ATTRIBUTE_TYPES: typing.Dict = {
            {%- for attr in tableDescription %}
            "{{ attr['Field'] }}": {{ attr['ModelType'] }},
            {%- endfor %}
        }
        {%- if enumTypes %}
        ATTRIBUTE_ENUM_OPTIONS: typing.Dict = {
            {%- for item in enumTypes %}
            "{{ item['Field'] }}": ({{ item['Options'] }}),
            {%- endfor %}
        }{%- endif %}
        MODEL_DATA_CONVERTOR: typing.Dict = {
            {%- for key, value in modelConvertors.items() %}
            "{{ key }}": {{ value }},
            {%- endfor %}
        }

        # Class attribute to table attribute name conversion
        {%- for attr in tableDescription %}
        {{ attr['Field'] }}: str = "{{ attr['Field'] }}"
        {%- endfor %}

        {%- if enumTypes %}
        # Enum type attributes options
        {%- endif %}
        {%- for item in enumTypes %}
        {{ item['Field'] }}_enum_options: typing.List = ({{ item['Options'] }})
        {%- endfor %}

    def __init__(self, init_data: typing.Dict = {}):
        {%- for attr in tableDescription %}
        self.{{ attr['Field']}}{{ ": "+attr['ModelType'] if attr['ModelType'] else "" }} = {{ attr['ModelDefaultValue'] }}
        """{{ attr['Comment']+", " if attr['Comment'] }}Type: {{ attr['Type'] }}, Can be NULL: {{ attr['Null'] }}{{ ", Key: "+attr['Key'] if attr['Key'] }}{{ ", Default: "+attr['Default'] if attr['Default'] }}{{ ", Extra info: "+attr['Extra'] if attr['Extra'] }}"""
        {%- endfor %}
        super().__init__(init_data)

