{#
    Custom Filters Available in This Template:
    - camel_case: Converts a string to camelCase (e.g., 'phone_number' → 'phoneNumber').
    - pascal_case: Converts a string to PascalCase (e.g., 'phone_number' → 'PhoneNumber').
    - kebab_case: Converts a string to kebab-case (e.g., 'phoneNumber' → 'phone-number').
    - snake_case: Converts a string to snake_case (e.g., 'PhoneNumber' → 'phone_number').
    - get_model_file_name: Generates a model file name (e.g., 'phone_number' → 'PhoneNumberModel.ts').
#}
{%- include 'header.jinja2' %}

import type { ToJSON } from 'stellanow-sdk';
import { StellaNowMessageBase, Converters, EntityType } from 'stellanow-sdk';
{%- for model in spec.referenced_models %}
import type { {{ model | pascal_case }}Model } from './models/{{ model | get_model_file_name }}.{{ spec.file_ext }}';
{%- endfor %}

export class {{ spec.name | pascal_case }}Message extends StellaNowMessageBase implements ToJSON {
    constructor({%- for entity in spec.entities %}
        public readonly {{ entity.mapped_name }}: string{% if not loop.last or spec.fields %},{% endif %}{%- endfor %}{% for field in spec.fields %}
        public readonly {{ field.mapped_name | snake_case }}: {{ field.type_str }}{% if not loop.last %},{% endif %}{%- endfor %}
    ) {
        super('{{ spec.name }}', [{%- for entity in spec.entities %}new EntityType('{{ entity.original_name }}', {{ entity.mapped_name }}){% if not loop.last %}, {% endif %}{%- endfor %}]);
    }

    public toJSON(): object {
        return {
            {%- for field in spec.fields %}
            {{ field.original_name }}: Converters.convert(this.{{ field.mapped_name | snake_case }}),
            {%- endfor %}
            ...super.toJSON(),
        };
    }
}

{%- include 'footer.jinja2' -%}