from ......Internal.Core import Core
from ......Internal.CommandsGroup import CommandsGroup
from ......Internal import Conversions


# noinspection PyPep8Naming,PyAttributeOutsideInit,SpellCheckingInspection
class DigitalCls:
	"""Digital commands group definition. 8 total commands, 3 Subgroups, 4 group commands"""

	def __init__(self, core: Core, parent):
		self._core = core
		self._cmd_group = CommandsGroup("digital", core, parent)

	@property
	def iqRatio(self):
		"""iqRatio commands group. 0 Sub-classes, 1 commands."""
		if not hasattr(self, '_iqRatio'):
			from .IqRatio import IqRatioCls
			self._iqRatio = IqRatioCls(self._core, self._cmd_group)
		return self._iqRatio

	@property
	def leakage(self):
		"""leakage commands group. 0 Sub-classes, 2 commands."""
		if not hasattr(self, '_leakage'):
			from .Leakage import LeakageCls
			self._leakage = LeakageCls(self._core, self._cmd_group)
		return self._leakage

	@property
	def quadrature(self):
		"""quadrature commands group. 0 Sub-classes, 1 commands."""
		if not hasattr(self, '_quadrature'):
			from .Quadrature import QuadratureCls
			self._quadrature = QuadratureCls(self._core, self._cmd_group)
		return self._quadrature

	def get_delay(self) -> float:
		"""SCPI: [SOURce]:BB:IMPairment:DIGital:DELay \n
		Snippet: value: float = driver.source.bb.impairment.digital.get_delay() \n
		Defines the time delay of both I and Q vectors between the marker signal at the marker outputs relative to the signal
		generation start. A positive value means that the I and Q vectors delay relative to the marker/trigger and vice versa.
		Value range
			Table Header: Output / Min /s / Max /s / Increment \n
			- RF<ch> / 0 / 10E-6 / 1E-12
			- IQOutput<ch> / 500E-9 / 500E-9 / 1E-12
			- DIGital / 500E-9 / 500E-9 / 1E-12 \n
			:return: delay: float Range: 0 to 10E-6
		"""
		response = self._core.io.query_str('SOURce:BB:IMPairment:DIGital:DELay?')
		return Conversions.str_to_float(response)

	def set_delay(self, delay: float) -> None:
		"""SCPI: [SOURce]:BB:IMPairment:DIGital:DELay \n
		Snippet: driver.source.bb.impairment.digital.set_delay(delay = 1.0) \n
		Defines the time delay of both I and Q vectors between the marker signal at the marker outputs relative to the signal
		generation start. A positive value means that the I and Q vectors delay relative to the marker/trigger and vice versa.
		Value range
			Table Header: Output / Min /s / Max /s / Increment \n
			- RF<ch> / 0 / 10E-6 / 1E-12
			- IQOutput<ch> / 500E-9 / 500E-9 / 1E-12
			- DIGital / 500E-9 / 500E-9 / 1E-12 \n
			:param delay: float Range: 0 to 10E-6
		"""
		param = Conversions.decimal_value_to_str(delay)
		self._core.io.write(f'SOURce:BB:IMPairment:DIGital:DELay {param}')

	def get_poffset(self) -> float:
		"""SCPI: [SOURce]:BB:IMPairment:DIGital:POFFset \n
		Snippet: value: float = driver.source.bb.impairment.digital.get_poffset() \n
		Adds an additional phase offset after the stream mapper.
			INTRO_CMD_HELP: You can shift the phase at the different stages in the signal generation flow, see: \n
			- [:SOURce<hw>]:BB:POFFset \n
			:return: phase_offset: float Range: -999.99 to 999.99
		"""
		response = self._core.io.query_str('SOURce:BB:IMPairment:DIGital:POFFset?')
		return Conversions.str_to_float(response)

	def set_poffset(self, phase_offset: float) -> None:
		"""SCPI: [SOURce]:BB:IMPairment:DIGital:POFFset \n
		Snippet: driver.source.bb.impairment.digital.set_poffset(phase_offset = 1.0) \n
		Adds an additional phase offset after the stream mapper.
			INTRO_CMD_HELP: You can shift the phase at the different stages in the signal generation flow, see: \n
			- [:SOURce<hw>]:BB:POFFset \n
			:param phase_offset: float Range: -999.99 to 999.99
		"""
		param = Conversions.decimal_value_to_str(phase_offset)
		self._core.io.write(f'SOURce:BB:IMPairment:DIGital:POFFset {param}')

	def get_skew(self) -> float:
		"""SCPI: [SOURce]:BB:IMPairment:DIGital:SKEW \n
		Snippet: value: float = driver.source.bb.impairment.digital.get_skew() \n
		Sets a delay between the Q vector and the I vector of the corresponding stream. \n
			:return: skew: float Range: -500E-9 to 500E-9
		"""
		response = self._core.io.query_str('SOURce:BB:IMPairment:DIGital:SKEW?')
		return Conversions.str_to_float(response)

	def set_skew(self, skew: float) -> None:
		"""SCPI: [SOURce]:BB:IMPairment:DIGital:SKEW \n
		Snippet: driver.source.bb.impairment.digital.set_skew(skew = 1.0) \n
		Sets a delay between the Q vector and the I vector of the corresponding stream. \n
			:param skew: float Range: -500E-9 to 500E-9
		"""
		param = Conversions.decimal_value_to_str(skew)
		self._core.io.write(f'SOURce:BB:IMPairment:DIGital:SKEW {param}')

	def get_state(self) -> bool:
		"""SCPI: [SOURce]:BB:IMPairment:DIGital:STATe \n
		Snippet: value: bool = driver.source.bb.impairment.digital.get_state() \n
		Activates the impairment or correction values LEAKage, QUADrature and IQRatio for the corresponding stream. \n
			:return: state: 1| ON| 0| OFF
		"""
		response = self._core.io.query_str('SOURce:BB:IMPairment:DIGital:STATe?')
		return Conversions.str_to_bool(response)

	def set_state(self, state: bool) -> None:
		"""SCPI: [SOURce]:BB:IMPairment:DIGital:STATe \n
		Snippet: driver.source.bb.impairment.digital.set_state(state = False) \n
		Activates the impairment or correction values LEAKage, QUADrature and IQRatio for the corresponding stream. \n
			:param state: 1| ON| 0| OFF
		"""
		param = Conversions.bool_to_str(state)
		self._core.io.write(f'SOURce:BB:IMPairment:DIGital:STATe {param}')

	def clone(self) -> 'DigitalCls':
		"""Clones the group by creating new object from it and its whole existing subgroups
		Also copies all the existing default Repeated Capabilities setting,
		which you can change independently without affecting the original group"""
		new_group = DigitalCls(self._core, self._cmd_group.parent)
		self._cmd_group.synchronize_repcaps(new_group)
		return new_group
