from opentrons.protocol_api import Labware, WasteChute, TrashBin
from opentrons.protocol_api.protocol_context import ModuleTypes
from ..data.dbo.labware import LabwareWrapper
from ..data.dbo.module import ModuleWrapper
from ..data.dbo.instrument import InstrumentWrapper
from ..data.dbo.trashbin import TrashBinWrapper


def get_location_from_str(string: str):
    if string.isnumeric():
        return int(string)
    else:
        return string

def convert_generic_to_labware_module_trash(generic:  LabwareWrapper | ModuleWrapper | InstrumentWrapper | TrashBinWrapper | WasteChute | None) -> Labware | ModuleTypes | WasteChute | TrashBin:
    if isinstance(generic, LabwareWrapper):
        return generic.labware_instance
    if isinstance(generic, ModuleWrapper):
        return generic.module_instance
    if isinstance(generic, TrashBinWrapper):
        return generic.trash_bin_instance
    if isinstance(generic, WasteChute):
        return generic
    raise RuntimeError("Id is not valid for this request")