from typing import Optional
from backend.condition.condition_trigger_request import ConditionFileType
from backend.condition.domain.mapping.lbwf.lbwf_mapper import LbwfMapper
from backend.condition.domain.mapping.mapper import Mapper
from backend.condition.domain.mapping.peabody.peabody_mapper import PeabodyMapper
from backend.condition.lookups.uprn_lookup import UprnLookup
from backend.condition.parsing.parser import Parser
from backend.condition.parsing.lbwf_parser import LbwfParser
from backend.condition.parsing.peabody_parser import PeabodyParser


def select_parser(
    file_type: ConditionFileType, uprn_lookup: Optional[UprnLookup] = None
) -> Parser:
    if file_type is ConditionFileType.LBWF:
        return LbwfParser()

    if file_type is ConditionFileType.Peabody:
        if not uprn_lookup:
            raise ValueError(
                "Cannot instantiate Peabody Parser without UPRN lookup being provided"
            )
        return PeabodyParser(uprn_lookup=uprn_lookup)

    raise ValueError("Unrecognised file type, unable to instantiate Parser")


def select_mapper(file_type: ConditionFileType) -> Mapper:
    if file_type is ConditionFileType.LBWF:
        return LbwfMapper()

    if file_type is ConditionFileType.Peabody:
        return PeabodyMapper()

    raise ValueError("Unrecognised file type, unable to instantiate Mapper")
