{# Product block definition -#}

{% from 'macros.j2' import required, default, lifecycle_type, type_and_default, list_field with context -%}

from enum import StrEnum, IntEnum
from typing import Annotated
from uuid import UUID

from annotated_types import Ge, Le, Len
from orchestrator.domain.base import ProductBlockModel
from orchestrator.types import SI, SubscriptionLifecycle
from pydantic import computed_field

{%- for namespace, type in types_to_import %}
from {{ namespace }} import {{ type }}
{%- endfor %}
{% for module, type in product_blocks_to_import -%}
from {{ module }} import {{ type }}BlockInactive, {{ type }}BlockProvisioning, {{ type }}Block
{% endfor %}

{% include "enums.j2" %}
{% include "list_definitions.j2" %}
{% include "constrained_int_definitions.j2" %}

class {{ product_block.type }}BlockInactive(ProductBlockModel, product_block_name="{{ product_block.block_name }}"):
    {% for field in fields -%}
    {% if field.type == "list" -%}
    {{ list_field(field.name, lifecycle_type(field.list_type, product_block_types, "Inactive")) }}
    {% else -%}
    {% set type = lifecycle_type(field.type, product_block_types, "Inactive") -%}
    {{ field.name }}: {{ required(field, type, ["inactive"]) }} {{ default(field) }}
    {% endif -%}
    {% endfor %}

class {{ product_block.type }}BlockProvisioning({{ product_block.type }}BlockInactive, lifecycle=[SubscriptionLifecycle.PROVISIONING]):
    {% for field in fields -%}
    {% if field.type == "list" -%}
    {{ list_field(field.name, lifecycle_type(field.list_type, product_block_types, "Provisioning")) }}
    {% else -%}
    {% set type = lifecycle_type(field.type, product_block_types, "Provisioning") -%}
    {{ field.name }}: {{ type_and_default(field, type, ["inactive", "provisioning"]) }}
    {% endif -%}
    {% endfor %}
    @computed_field
    @property
    def title(self) -> str:
        # TODO: format correct title string
        return f"{self.name}"


class {{ product_block.type }}Block({{ product_block.type }}BlockProvisioning, lifecycle=[SubscriptionLifecycle.ACTIVE]):
    {% for field in fields -%}
    {% if field.type == "list" -%}
    {{ list_field(field.name, lifecycle_type(field.list_type, product_block_types, "")) }}
    {% else -%}
    {% set type = lifecycle_type(field.type, product_block_types, "") -%}
    {{ field.name }}: {{ type_and_default(field, type, ["inactive", "provisioning", "active"]) }}
    {% endif -%}
    {% endfor %}
