// AUTO-GENERATED by djino. Do not edit manually.
// Generated from: {{ model_key }}

import { Model, Manager } from '@djino/core';
import {
{% for cls in descriptor_imports | sort %}
  {{ cls }},
{% endfor %}
} from '@djino/core/fields';
{% for imp in model_imports %}
import { {{ imp.type_name }} } from './{{ imp.file_name }}';
{% endfor %}

// --- Data Interface ---
{% for choice in choice_types %}

export type {{ choice.name }} = {{ choice.union }};
{% endfor %}

export interface {{ model_name }}Data {
{% for field in fields %}
{% if field.is_relation and field.descriptor_class == 'ManyToManyField' %}
{% elif field.choice_type_name %}
  {{ field.column }}: {{ field.choice_type_name }};
{% else %}
  {{ field.column }}: {{ field.ts_type }};
{% endif %}
{% endfor %}
}

// --- Field Descriptors ---

export const {{ model_name }}Fields = {
{% for field in fields %}
{% if field.choice_type_name %}
  {{ field.name }}: new {{ field.descriptor_class }}<{{ model_name }}Data, {{ field.choice_type_name }}>('{{ field.column }}'),
{% elif field.descriptor_extra_args %}
  {{ field.name }}: new {{ field.descriptor_class }}<{{ model_name }}Data>('{{ field.column }}', {{ field.descriptor_extra_args | join(', ') }}),
{% else %}
  {{ field.name }}: new {{ field.descriptor_class }}<{{ model_name }}Data>('{{ field.column }}'),
{% endif %}
{% endfor %}
} as const;

// --- Model Class ---

export class {{ model_name }} extends Model<{{ model_name }}Data> {
  static readonly _meta = {
    appLabel: '{{ app_label }}',
    modelName: '{{ model_name }}',
    dbTable: '{{ db_table }}',
    fields: {{ model_name }}Fields,
    syncScope: '{{ sync_scope }}',
{% if owner_field %}
    ownerField: '{{ owner_field }}',
{% endif %}
  };

  static objects = new Manager<{{ model_name }}Data, typeof {{ model_name }}Fields>({{ model_name }});
}
