# SPDX-FileCopyrightText: 2020 The Magma Authors.
# SPDX-FileCopyrightText: 2022 Open Networking Foundation <support@opennetworking.org>
#
# SPDX-License-Identifier: BSD-3-Clause

import json
from typing import Any, List

from data_models.data_model import DataModel
from data_models.data_model_parameters import ParameterName

from collections import namedtuple

from lte_utils import DuplexMode, map_earfcndl_to_band_earfcnul_mode

from exceptions import ConfigurationError
from logger import EnodebdLogger as logger


SingleEnodebConfig = namedtuple(
    'SingleEnodebConfig',
    [
        'earfcndl', 'subframe_assignment',
        'special_subframe_pattern',
        'pci', 'plmnid_list', 'tac',
        'bandwidth_mhz', 'cell_id',
        'allow_enodeb_transmit',
        'mme_address', 'mme_port',
    ],
)

class EnodebConfiguration():
    """
    This represents the data model configuration for a single
    eNodeB device. This can correspond to either the current configuration
    of the device, or what configuration we desire to have for the device.
    """

    def __init__(self, data_model: DataModel) -> None:
        """
        The fields initialized in the constructor here should be enough to
        track state across any data model configuration.

        Most objects for eNodeB data models cannot be added or deleted.
        For those objects, we just track state with a simple mapping from
        parameter name to value.

        For objects which can be added/deleted, we track them separately.
        """

        # DataModel
        self._data_model = data_model

        # Dict[ParameterName, Any]
        self._param_to_value = {}

        # Dict[ParameterName, Dict[ParameterName, Any]]
        self._numbered_objects = {}
        # If adding a PLMN object, then you would set something like
        # self._numbered_objects['PLMN_1'] = {'PLMN_1_ENABLED': True}

    @property
    def data_model(self) -> DataModel:
        """
        The data model configuration is tied to a single data model
        """
        return self._data_model

    def get_parameter_names(self) -> List[ParameterName]:
        """
        Returns: list of ParameterName
        """
        return list(self._param_to_value.keys())

    def has_parameter(self, param_name: ParameterName) -> bool:
        return param_name in self._param_to_value

    def get_parameter(self, param_name: ParameterName) -> Any:
        """
        Args:
            param_name: ParameterName
        Returns:
            Any, value of the parameter, formatted to be understood by enodebd
        """
        self._assert_param_in_model(param_name)
        return self._param_to_value[param_name]

    def set_parameter(
        self,
        param_name: ParameterName,
        value: Any,
    ) -> None:
        """
        Args:
            param_name: the parameter name to configure
            value: the value to set, formatted to be understood by enodebd
        """
        self._assert_param_in_model(param_name)
        self._param_to_value[param_name] = value

    def set_parameter_if_present(self, parameter_name: ParameterName, value: Any) -> None:
        """
        Args:
            param_name: the parameter name to configure
            value: the value to set, formatted to be understood by enodebd
        """

        trparam_model = self.data_model
        tr_param = trparam_model.get_parameter(parameter_name)
        if tr_param is not None:
            self._param_to_value[parameter_name] = value

    def delete_parameter(self, param_name: ParameterName) -> None:
        del self._param_to_value[param_name]

    def get_object_names(self) -> List[ParameterName]:
        return list(self._numbered_objects.keys())

    def has_object(self, param_name: ParameterName) -> bool:
        """
        Args:
            param_name: The ParameterName of the object
        Returns: True if set in configuration
        """
        self._assert_param_in_model(param_name)
        return param_name in self._numbered_objects

    def add_object(self, param_name: ParameterName) -> None:
        if param_name in self._numbered_objects:
            raise ConfigurationError("Configuration already has object")
        self._numbered_objects[param_name] = {}

    def delete_object(self, param_name: ParameterName) -> None:
        if param_name not in self._numbered_objects:
            raise ConfigurationError("Configuration does not have object")
        del self._numbered_objects[param_name]

    def get_parameter_for_object(
        self,
        param_name: ParameterName,
        object_name: ParameterName,
    ) -> Any:
        return self._numbered_objects[object_name].get(param_name)

    def set_parameter_for_object(
        self,
        param_name: ParameterName,
        value: Any,
        object_name: ParameterName,
    ) -> None:
        """
        Args:
            param_name: the parameter name to configure
            value: the value to set, formatted to be understood by enodebd
            object_name: ParameterName of object
        """
        self._assert_param_in_model(object_name)
        self._assert_param_in_model(param_name)
        self._numbered_objects[object_name][param_name] = value

    def get_parameter_names_for_object(
        self,
        object_name: ParameterName,
    ) -> List[ParameterName]:
        return list(self._numbered_objects[object_name].keys())

    def get_debug_info(self) -> str:
        debug_info = 'Param values: {}, \n Object values: {}'
        return debug_info.format(
            json.dumps(self._param_to_value, indent=2),
            json.dumps(
                self._numbered_objects,
                indent=2,
            ),
        )

    def _assert_param_in_model(self, param_name: ParameterName) -> None:
        trparam_model = self.data_model
        tr_param = trparam_model.get_parameter(param_name)
        if tr_param is None:
            logger.warning('Parameter <%s> not defined in model', param_name)
            raise ConfigurationError("Parameter %s not defined in model." % param_name)

    def check_desired_configuration(self, current_config, desired_config: dict) -> bool:
        def config_assert(condition: bool, message: str = None) -> None:
            """ To be used in place of 'assert' so that ConfigurationError is raised
                for all config-related exceptions. """
            if not condition:
                raise ConfigurationError(message)

        # _set_earfcn_freq_band_mode
        # Originally: 
        # mconfig: loaded from proto definiation
        # service_config: loaded from mconfig
        # device_config: retrieved configuration from enodeb
        # data_model: defined in device parameter
    
        # device_config = config loaded from enodeb, desired_config = config loaded from file

        # _check_earfcn_freqw_band_mode
        try:
            band, duplex_mode, _ = map_earfcndl_to_band_earfcnul_mode(desired_config["earfcn_downlink1"])
        except ValueError as err:
            raise ConfigurationError(err)

        if current_config.has_parameter(ParameterName.DUPLEX_MODE_CAPABILITY):
            duplex_capability = current_config.get_parameter(ParameterName.DUPLEX_MODE_CAPABILITY)
            if duplex_mode == DuplexMode.TDD and duplex_capability != "TDDMode":
                raise ConfigurationError("Duplex mode TDD is not supported by eNodeB")
            elif duplex_mode == DuplexMode.FDD and duplex_capability != "FDDMode":
                raise ConfigurationError("Duplex mode FDD is not supported by eNodeB")
            elif duplex_mode not in [DuplexMode.TDD, DuplexMode.FDD]:
                raise ConfigurationError("Invalid duplex mode")
        
        if current_config.has_parameter(ParameterName.BAND_CAPABILITY):
            band_capability = current_config.get_parameter(ParameterName.BAND_CAPABILITY).split(',')
            if str(band) not in band_capability:
                logger.warning("Band %d not in capability list %s", band, band_capability)

        # _check_tdd_subframe_config
        config_assert(
            desired_config["subframe_assignment"] in range(0, 7),
            "Invalid TDD special subframe assignment (%d)" % desired_config["subframe_assignment"],
        )
        config_assert(
            desired_config["special_subframe_pattern"] in range(0, 10),
            "Invalid TDD special subframe pattern (%d)" % desired_config["special_subframe_pattern"],
        )
        
        # _check_plmnids_tac
        for char in str(desired_config["plmn_list"]):
            config_assert(char in "0123456789, ", "Invalid PLMNID (%s)" % desired_config["plmn_list"])
        
        # TODO - add support for multiple PLMNIDs
        plmnid_list = str(desired_config["plmn_list"]).split(",")
        config_assert(len(plmnid_list) == 1, "Only 1 PLMNID is supported")
        config_assert(len(plmnid_list[0]) <= 6, "PLMNID must be length <= 6 (%s)" % plmnid_list[0])

        # _check_s1_connection_configuration
        config_assert(type(desired_config["mme_address"]) is str, "Invalid MME address")
        config_assert(type(desired_config["mme_port"]) is int, "Invalid MME port")

    def apply_desired_configuration(self, current_config, desired_config: SingleEnodebConfig) -> None:
        
        # _set_earfcn_freq_band_mode
        self.set_parameter(ParameterName.EARFCNDL, desired_config["earfcn_downlink1"])
        band, duplex_mode, _ = map_earfcndl_to_band_earfcnul_mode(desired_config["earfcn_downlink1"])
        if duplex_mode == DuplexMode.FDD:
            self.set_parameter(ParameterName.EARFCNUL, desired_config["earfcn_uplink1"])
        self.set_parameter_if_present(ParameterName.BAND, band)

        # _set_tdd_subframe_config
        if (current_config.has_parameter(ParameterName.DUPLEX_MODE_CAPABILITY)
            and current_config.get_parameter(ParameterName.DUPLEX_MODE_CAPABILITY) == "TDDMode"):
            self.set_parameter(ParameterName.SUBFRAME_ASSIGNMENT, desired_config["subframe_assignment"])
            self.set_parameter(ParameterName.SPECIAL_SUBFRAME_PATTERN, desired_config["special_subframe_pattern"])
        
        # _set_plmnids_tac
        plmnid_list = str(desired_config["plmn_list"]).split(",")
        for i in range(1, 2):
            object_name = ParameterName.PLMN_N % i
            enable_plmn = i == 1
            self.add_object(object_name)
            self.set_parameter_for_object(ParameterName.PLMN_N_ENABLE % i, enable_plmn, object_name)
            if enable_plmn:
                self.set_parameter_for_object(ParameterName.PLMN_N_CELL_RESERVED % i, False, object_name)
                self.set_parameter_for_object(ParameterName.PLMN_N_PRIMARY % i, enable_plmn, object_name)
                self.set_parameter_for_object(ParameterName.PLMN_N_PLMNID % i, plmnid_list[i - 1], object_name)
        self.set_parameter(ParameterName.TAC1, desired_config["tac1"])

        # _set_bandwidth
        self.set_parameter(ParameterName.DL_BANDWIDTH, desired_config["downlink_bandwidth"])
        self.set_parameter(ParameterName.UL_BANDWIDTH, desired_config["uplink_bandwidth"])

        # _set_cell_id
        self.set_parameter(ParameterName.CELL_ID, desired_config["cell_id"])

        # _set_misc_static_params
        self.set_parameter_if_present(ParameterName.LOCAL_GATEWAY_ENABLE, 0)
        self.set_parameter_if_present(ParameterName.GPS_ENABLE, True)
        self.set_parameter_if_present(ParameterName.IP_SEC_ENABLE, False)
        self.set_parameter_if_present(ParameterName.CELL_RESERVED, False)
        self.set_parameter_if_present(ParameterName.MME_POOL_ENABLE, False)

        # _set_s1_connection_configuration
        self.set_parameter(ParameterName.MME_ADDRESS, desired_config["mme_address"])
        self.set_parameter(ParameterName.MME_PORT, desired_config["mme_port"])

        # enable LTE if we should
        self.set_parameter(ParameterName.ADMIN_STATE, desired_config["admin_state"])

        # These parameters are already configured at above
        exclude_list = [
            "earfcn_downlink1", "earfcn_uplink1", "subframe_assignment", "special_subframe_pattern",
            "plmnid", "tac1", "downlink_bandwidth", "uplink_bandwidth", "cell_id",
            "mme_address", "mme_port", "admin_state"
        ]

        # Configure the additional parameters which are set in enodeb config files
        for name, value in desired_config.items():
            if name not in exclude_list:
                self.set_parameter_if_present(name, value)
