#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from typing import Self, Any, Callable
from Interfaces.OpoTestsInterface import OpoTestsInterface
from Models.RequestModel import RequestModel

class ControllersAbstract:

    def __init__(self:Self, 
        ot:OpoTestsInterface, 
        actions:dict[str, Callable[[RequestModel], tuple[Any|None, dict[str, Any|None]]]]
    ) -> None:
        self.ot:OpoTestsInterface = ot
        self.__actions:dict[str, Callable[[RequestModel], tuple[Any|None, dict[str, Any|None]]]] = actions

    def add(self:Self, key:str, action:Callable[[RequestModel], tuple[Any|None, dict[str, Any|None]]], overwrite:bool = False) -> None:
        if overwrite or key not in self.__actions:
            self.__actions[key] = action

    def get(self:Self, 
        key:str, 
        request:RequestModel
    ) -> tuple[Any|None, dict[str, Any|None]]|None:
        return self.__actions[key](request) if key in self.__actions else None