{# Terminate workflow -#}

import structlog
from pydantic import AfterValidator, ConfigDict, model_validator
from pydantic_forms.types import InputForm, State, UUIDstr

from orchestrator.forms import FormPage
from orchestrator.forms.validators import DisplaySubscription
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__)


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

    class Terminate{{ product.type }}Form(FormPage):
        subscription_id: DisplaySubscription = temp_subscription_id  # type: ignore
{% include "additional_terminate_input_fields.j2" ignore missing -%}
        {%- for validation in workflow_validations %}

        @model_validator(mode="after")
        def {{ validation.id }}(self) -> "Terminate{{ product.type }}Form":
            if False:  # TODO implement validation
                raise ValueError("{{ validation.description }}")
            return self

        {%- endfor %}

    return Terminate{{ product.type }}Form


@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
    )
