from loguru import logger

from slic.devices.xoptics.aramis_attenuator import Attenuator
from slic.devices.xoptics.pulsepicker import PulsePicker
from slic.devices.xdiagnostics.intensitymonitor import IntensityMonitorPBPS
#from .Cristallina_mono import CristallinaMono
from .cristallina_mono import CristallinaMono
from .alignment_laser import AlignmentLaser

from slic.devices.xoptics.kb import KBHor, KBVer
from slic.devices.xoptics.offsetmirrors import OffsetMirror
from slic.devices.xoptics.slits import SlitUnitCenterWidth

from .pp_shutter import PP_Shutter
from .i0_chamber import i0_chamber
from .apertures import slits107, slits149

# Attenuators
upstream_attenuator = Attenuator("SARFE10-OATT053", description="Aramis attenuator OATT053")
attenuator = Attenuator("SAROP31-OATA150", description="Cristallina attenuator OATA150")

def test_attenuators():
    for att in (upstream_attenuator, attenuator):
        tfundamental = att.get_transmission()
        try:
            assert tfundamental > 0
        except TypeError:
            logger.warning(f"No transmission value reported from {att.ID}")

test_attenuators()

# Shutter
pp_shutter = PP_Shutter(
    "SARES30-LTIM01-EVR0:RearUniv0-Ena-SP", name="Cristallina pulse picker shutter"
)  # Shutter button when ufasing the pulse picker


pulsepicker = PulsePicker(
    "SAROP31-OPPI151",
    "SARES30-LTIM01-EVR0:Pul3",
    name="Cristallina X-ray pulse picker OPPI151",
)


# Alignment laser
alignment_laser = AlignmentLaser(
    "SAROP31-OLAS147:MOTOR_1", name="Cristallina alignment laser OLAS147"
)

pbps113 = IntensityMonitorPBPS(
    "SAROP31-PBPS113",
    # vme_crate="SAROP31-CVME-PBPS1", # please check this!
    # link=9,
    description="Intensity/position monitor in the optics hutch",
)

pbps149 = IntensityMonitorPBPS(
    "SAROP31-PBPS149",
    # vme_crate="SAROP31-CVME-PBPS2", # please check this!
    # link=9,
    description="Intensity/position monitor in the experimental hutch",
)

# I0 chamber
i0 = i0_chamber('SARES30-MCS20610')

# Slits
slits149 = SlitUnitCenterWidth('SAROP31-OAPU149')
slits107 = SlitUnitCenterWidth('SAROP31-OAPU107')
slitsi0 =  i0.slits

# KB mirrors
kbHor = KBHor("SAROP31-OKBH154", description="Cristallina horizontal KB mirror")
kbVer = KBVer("SAROP31-OKBV153", description="Cristallina vertical KB mirror")

# Mono
mono = CristallinaMono("SAROP31-ODCC110")

# Offset mirrors
m3 = OffsetMirror('SAROP31-ODMV152')
#TODO the other two offset mirros

