"""__init__.py module for the If true then empty plugin."""
# WARNING - DO NOT EDIT - YOUR CHANGES WILL NOT BE PROTECTED.
# This file is auto-generated by the aac gen-plugin and may be overwritten.

from os.path import join, dirname
from copy import deepcopy
from typing import Any
from aac.execute.aac_execution_result import (
    ExecutionResult,
)
from aac.execute import hookimpl
from aac.context.language_context import LanguageContext
from aac.context.definition import Definition
from aac.execute.plugin_runner import PluginRunner
from aac.plugins.if_true_then_empty.if_true_then_empty_impl import plugin_name
from aac.plugins.if_true_then_empty.if_true_then_empty_impl import if_true_then_empty


if_true_then_empty_aac_file_name = "if_true_then_empty.aac"


def run_if_true_then_empty(
    instance: Any, definition: Definition, defining_schema, arguments: Any
) -> ExecutionResult:
    """Check to ensure the empty_field_name is empty if bool_field_name is true."""

    argument_copy = deepcopy(arguments)
    args = {}
    for arg in argument_copy:
        args[arg["name"]] = arg["value"]

    return if_true_then_empty(instance, definition, defining_schema, **args)


@hookimpl
def register_plugin() -> None:
    """
    Returns information about the plugin.

    Returns:
        A collection of information about the plugin and what it contributes.
    """

    active_context = LanguageContext()
    if_true_then_empty_aac_file = join(
        dirname(__file__), if_true_then_empty_aac_file_name
    )
    definitions = active_context.parse_and_load(if_true_then_empty_aac_file)

    if_true_then_empty_plugin_definition = [
        definition for definition in definitions if definition.name == plugin_name
    ][0]

    plugin_instance = if_true_then_empty_plugin_definition.instance
    for file_to_load in plugin_instance.definition_sources:
        active_context.parse_and_load(file_to_load)

    plugin_runner = PluginRunner(plugin_definition=if_true_then_empty_plugin_definition)

    plugin_runner.add_constraint_callback("If true then empty", run_if_true_then_empty)

    active_context.register_plugin_runner(plugin_runner)
