{# Terminate workflow -#}

{%-if validations %}
from uuid import UUID
from pydantic import root_validator
{% endif %}
import structlog
from orchestrator.forms import FormPage
from orchestrator.forms.validators import DisplaySubscription
from orchestrator.types import InputForm, State, UUIDstr
from orchestrator.workflow import StepList, begin, step
from orchestrator.workflows.utils import terminate_workflow

from {{ product_types_module }}.{{ product.variable }} import {{ product.type }}
{% include 'additional_terminate_imports.j2' ignore missing %}

logger = structlog.get_logger(__name__)


{% if validations -%}
{% for validation in validations %}
def validate_{{ validation.id }}(cls: FormPage, values: dict) -> dict:
    # TODO: add validation for "{{ validation.description }}"
    if True:
        raise ValueError({{ validation.description }})

    return values
{% endfor %}
{% endif -%}

def terminate_initial_input_form_generator(subscription_id: UUIDstr, customer_id: UUIDstr) -> InputForm:
    temp_subscription_id = subscription_id

    class TerminateForm(FormPage):
        subscription_id: DisplaySubscription = temp_subscription_id  # type: ignore
{% include "additional_terminate_input_fields.j2" ignore missing -%}

        {% for validation in validations %}
        _check_{{ validation.id }}: classmethod = root_validator(allow_reuse=True)(validate_{{ validation.id }})
        {% endfor %}
    return TerminateForm


@step("Delete subscription from OSS/BSS")
def delete_subscription_from_oss_bss(subscription: {{ product.type }}) -> State:
    # TODO: add actual call to OSS/BSS to delete subscription

    return {}


{% include 'additional_terminate_steps.j2' %}


@terminate_workflow("Terminate {{ product.name }}", initial_input_form=terminate_initial_input_form_generator, additional_steps=additional_steps)
def terminate_{{ product.variable }}() -> StepList:
    return (
        begin
        >> delete_subscription_from_oss_bss
        # TODO: fill in additional steps if needed
    )
