#######################################################################################
# Copyright ETSI Contributors and Others.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.


import asynctest
import logging
from osm_common.dataclasses.temporal_dataclasses import VnfInstantiateInput
from osm_common.temporal_constants import (
    LCM_TASK_QUEUE,
    ACTIVITY_SET_VNF_MODEL,
    WORKFLOW_VNF_PREPARE,
)
from osm_lcm.temporal.vnf_workflows import VnfPrepareWorkflow
from temporalio import activity
from temporalio.testing import WorkflowEnvironment
from temporalio.worker import Worker

wf_input = VnfInstantiateInput(
    vnfr_uuid="86b53d92-4f5a-402e-8ac2-585ec6b64698",
    model_name="a-model-name",
)


@activity.defn(name=ACTIVITY_SET_VNF_MODEL)
async def set_vnf_model_mocked(set_vnf_model_input: VnfInstantiateInput) -> None:
    logging.debug(
        f"VNF {set_vnf_model_input.vnfr_uuid} model name is updated to {set_vnf_model_input.model_name}."
    )


class TestVnfPrepareWorkflow(asynctest.TestCase):
    async def setUp(self):
        self.env = await WorkflowEnvironment.start_time_skipping()
        self.client = self.env.client

    async def test_vnf_prepare_workflow(self):
        async with self.env:
            async with Worker(
                self.client,
                task_queue=LCM_TASK_QUEUE,
                workflows=[VnfPrepareWorkflow],
                activities=[set_vnf_model_mocked],
            ):
                await self.client.execute_workflow(
                    VnfPrepareWorkflow.run,
                    arg=wf_input,
                    id=f"{WORKFLOW_VNF_PREPARE}-{wf_input.vnfr_uuid}",
                    task_queue=LCM_TASK_QUEUE,
                )
