from typing import Dict

import pytest

from app.connectors.argo_workflow.models import WorkflowMetadataResponse, BevaringDatasettResponse


@pytest.fixture
def testobj_verify_overforingspakke_message() -> Dict[str, str]:
    return {
        "workflow_name": "verify-overforingspakke-kpr2b",
        "workflow_uid": "9b040ea9-0780-4807-886d-aba12bfbfbe6",
        "workflow_type": "verify-overforingspakke",
        "type_specific_data": {
            "invitasjon_ekstern_id": "59e92013-f3ed-4e9f-9af5-0afe2686bb87",
            "target_bucket": "test-bucket",
        }
    }


@pytest.fixture
def testobj_transfer_to_bevaring_message() -> Dict[str, str]:
    return {
        "workflow_name": "transfer-arkivuttrekk-to-bevaring-knkr5",
        "workflow_uid": "4f9c10ea-db2e-493f-9154-8b7205a4b435",
        "workflow_type": "transfer-arkivuttrekk-to-bevaring",
        "type_specific_data": {
            "overforingspakke_id": "76"
        }
    }


@pytest.fixture
def testobj_bevaring_datasett_message() -> Dict[str, str]:
    return {
        "overforingspakke_id": "39",
        "workflow_status": "Succeeded",
        "datasett_id": "2718b34f-69c3-4027-96dc-d345b747e986",
        "s3_path": "2718b34f-69c3-4027-96dc-d345b747e986/ip0",
        "s3_bucket": "mock-s3-bucket-name-0001"
    }


def test_workflow_metadata_response_of_type_verify_overforingspakke_from_string(testobj_verify_overforingspakke_message):
    """
    GIVEN   static example message with workflow type verify-overforingspakke
    WHEN    constructing an object of type WorkflowMetadataResponse
    THEN    verify that the fields are correct
    """
    workflow = WorkflowMetadataResponse(**testobj_verify_overforingspakke_message)
    assert workflow.workflow_name == testobj_verify_overforingspakke_message["workflow_name"] and \
           workflow.workflow_uid == testobj_verify_overforingspakke_message["workflow_uid"] and \
           workflow.workflow_type == testobj_verify_overforingspakke_message["workflow_type"] and \
           workflow.type_specific_data == testobj_verify_overforingspakke_message["type_specific_data"]


def test_workflow_metadata_response_from_string_without_bucket(testobj_transfer_to_bevaring_message):
    """
    GIVEN   static example message with workflow type transfer-arkivuttrekk-to-bevaring
    WHEN    constructing an object of type WorkflowMetadataResponse
    THEN    verify that the fields are correct
    """
    workflow = WorkflowMetadataResponse(**testobj_transfer_to_bevaring_message)
    assert workflow.workflow_name == testobj_transfer_to_bevaring_message["workflow_name"] and \
           workflow.workflow_uid == testobj_transfer_to_bevaring_message["workflow_uid"] and \
           workflow.workflow_type == testobj_transfer_to_bevaring_message["workflow_type"] and \
           workflow.type_specific_data == testobj_transfer_to_bevaring_message["type_specific_data"]


def test_bevaring_datasett_response_from_string(testobj_bevaring_datasett_message):
    """
    GIVEN   static example message with bevaring datasett data
    WHEN    constructing an object of type BevaringDatasettResponse
    THEN    verify that the fields are correct
    """
    bevaring_datasett = BevaringDatasettResponse(**testobj_bevaring_datasett_message)
    assert bevaring_datasett.overforingspakke_id == testobj_bevaring_datasett_message["overforingspakke_id"] and \
           bevaring_datasett.workflow_status == testobj_bevaring_datasett_message["workflow_status"] and \
           bevaring_datasett.datasett_id == testobj_bevaring_datasett_message["datasett_id"] and \
           bevaring_datasett.s3_path == testobj_bevaring_datasett_message["s3_path"] and \
           bevaring_datasett.s3_bucket == testobj_bevaring_datasett_message["s3_bucket"]

from typing import Dict

import pytest

from app.connectors.argo_workflow.models import WorkflowMetadataResponse, BevaringDatasettResponse


@pytest.fixture
def testobj_verify_overforingspakke_message() -> Dict[str, str]:
    return {
        "workflow_name": "verify-overforingspakke-kpr2b",
        "workflow_uid": "9b040ea9-0780-4807-886d-aba12bfbfbe6",
        "workflow_type": "verify-overforingspakke",
        "type_specific_data": {
            "invitasjon_ekstern_id": "59e92013-f3ed-4e9f-9af5-0afe2686bb87",
            "target_bucket": "test-bucket",
        }
    }


@pytest.fixture
def testobj_transfer_to_bevaring_message() -> Dict[str, str]:
    return {
        "workflow_name": "transfer-arkivuttrekk-to-bevaring-knkr5",
        "workflow_uid": "4f9c10ea-db2e-493f-9154-8b7205a4b435",
        "workflow_type": "transfer-arkivuttrekk-to-bevaring",
        "type_specific_data": {
            "overforingspakke_id": "76"
        }
    }


@pytest.fixture
def testobj_bevaring_datasett_message() -> Dict[str, str]:
    return {
        "overforingspakke_id": "39",
        "workflow_status": "Succeeded",
        "datasett_id": "2718b34f-69c3-4027-96dc-d345b747e986",
        "s3_path": "2718b34f-69c3-4027-96dc-d345b747e986/ip0",
        "s3_bucket": "mock-s3-bucket-name-0001"
    }


def test_workflow_metadata_response_of_type_verify_overforingspakke_from_string(testobj_verify_overforingspakke_message):
    """
    GIVEN   static example message with workflow type verify-overforingspakke
    WHEN    constructing an object of type WorkflowMetadataResponse
    THEN    verify that the fields are correct
    """
    workflow = WorkflowMetadataResponse(**testobj_verify_overforingspakke_message)
    assert workflow.workflow_name == testobj_verify_overforingspakke_message["workflow_name"] and \
           workflow.workflow_uid == testobj_verify_overforingspakke_message["workflow_uid"] and \
           workflow.workflow_type == testobj_verify_overforingspakke_message["workflow_type"] and \
           workflow.type_specific_data == testobj_verify_overforingspakke_message["type_specific_data"]


def test_workflow_metadata_response_from_string_without_bucket(testobj_transfer_to_bevaring_message):
    """
    GIVEN   static example message with workflow type transfer-arkivuttrekk-to-bevaring
    WHEN    constructing an object of type WorkflowMetadataResponse
    THEN    verify that the fields are correct
    """
    workflow = WorkflowMetadataResponse(**testobj_transfer_to_bevaring_message)
    assert workflow.workflow_name == testobj_transfer_to_bevaring_message["workflow_name"] and \
           workflow.workflow_uid == testobj_transfer_to_bevaring_message["workflow_uid"] and \
           workflow.workflow_type == testobj_transfer_to_bevaring_message["workflow_type"] and \
           workflow.type_specific_data == testobj_transfer_to_bevaring_message["type_specific_data"]


def test_bevaring_datasett_response_from_string(testobj_bevaring_datasett_message):
    """
    GIVEN   static example message with bevaring datasett data
    WHEN    constructing an object of type BevaringDatasettResponse
    THEN    verify that the fields are correct
    """
    bevaring_datasett = BevaringDatasettResponse(**testobj_bevaring_datasett_message)
    assert bevaring_datasett.overforingspakke_id == testobj_bevaring_datasett_message["overforingspakke_id"] and \
           bevaring_datasett.workflow_status == testobj_bevaring_datasett_message["workflow_status"] and \
           bevaring_datasett.datasett_id == testobj_bevaring_datasett_message["datasett_id"] and \
           bevaring_datasett.s3_path == testobj_bevaring_datasett_message["s3_path"] and \
           bevaring_datasett.s3_bucket == testobj_bevaring_datasett_message["s3_bucket"]

GIVEN   static example message with workflow type verify-overforingspakke     WHEN    constructing an object of type WorkflowMetadataResponse     THEN    verify that the fields are correct GIVEN   static example message with workflow type transfer-arkivuttrekk-to-bevaring     WHEN    constructing an object of type WorkflowMetadataResponse     THEN    verify that the fields are correct GIVEN   static example message with bevaring datasett data     WHEN    constructing an object of type BevaringDatasettResponse     THEN    verify that the fields are correct