from datatypes.epc.construction_age_band import EpcConstructionAgeBand
from datatypes.epc.floor import EpcFloorDescriptions


def unknown_floor_as_built(age_band: EpcConstructionAgeBand) -> EpcFloorDescriptions:
    year = age_band.start_year()

    if year >= 2003:
        return EpcFloorDescriptions.solid_insulated_assumed

    if year >= 1996:
        return EpcFloorDescriptions.solid_limited_insulation_assumed

    if year >= 1930:
        return EpcFloorDescriptions.solid_no_insulation_assumed

    return EpcFloorDescriptions.suspended_no_insulation_assumed


def unknown_floor_retrofitted(age_band: EpcConstructionAgeBand) -> EpcFloorDescriptions:
    year = age_band.start_year()

    if year >= 1930:
        return EpcFloorDescriptions.solid_insulated

    return EpcFloorDescriptions.suspended_insulated


def map_solid_floor_as_built(age_band: EpcConstructionAgeBand) -> EpcFloorDescriptions:
    year = age_band.start_year()

    if year >= 2003:
        return EpcFloorDescriptions.solid_insulated_assumed
    if year >= 1996:
        return EpcFloorDescriptions.solid_limited_insulation_assumed
    return EpcFloorDescriptions.solid_no_insulation_assumed


def map_suspended_floor_as_built(age_band: EpcConstructionAgeBand) -> EpcFloorDescriptions:
    year = age_band.start_year()

    if year >= 2003:
        return EpcFloorDescriptions.suspended_insulated_assumed
    if year >= 1996:
        return EpcFloorDescriptions.suspended_limited_insulation_assumed

    return EpcFloorDescriptions.suspended_no_insulation_assumed


as_built_floor_classifiers = {
    "Solid": map_solid_floor_as_built,
    "SuspendedTimber": map_suspended_floor_as_built,
    "SuspendedNotTimber": map_suspended_floor_as_built,
}

unknown_as_built_floor_classifiers = {
    "RetroFitted": unknown_floor_retrofitted,
    "AsBuilt": unknown_floor_as_built,
    "Unknown": unknown_floor_as_built,
}
