"""
Holds all WHSPAH exceptions.
"""

import os

class NoWHSPAHDeviceFound(OSError):
    """
    Gets raised when whspah.Transmitter() is called with no port,
    and no port could be automatically found.
    """

    def __init__(self):
        super().__init__('No WHSPAH device was found.')

class NotValidWHSPAHDevice(OSError):
    """
    Gets raised if the specified transmitter port is not a WHSPAH device.
    """

    def __init__(self, port: os.PathLike):
        super().__init__(f'{port} is not a WHSPAH device.')

class TransmitError(OSError):
    """
    Gets raised when transmitting to the device fails.
    This typically happens when trying to communicate with an unplugged device.
    """

    def __init__(self, port: os.PathLike):
        super().__init__(f'Failed to transmit to {port}.')

# ----- Transmit argument errors -----

class InvalidTransmitterID(ValueError):
    """
    Gets raised if the chosen transmitter ID is not within range.
    """

    def __init__(self, transmitterID: int):
        super().__init__(f'Transmitter ID {transmitterID} is not valid. '+
                          'Transmitter ID must be an int within the range 126 to 32767.')

class InvalidChannel(ValueError):
    """
    Gets raised if the chosen channel is not within range.
    """

    def __init__(self, channel: int):
        super().__init__(f'Channel {channel} is not valid.'+
                          ' Channel must be an int within the range 1 to 3.')

class InvalidMode(ValueError):
    """
    Gets raised if the chosen mode is not valid.
    """

    def __init__(self, mode: 'whspah.MODES'):
        super().__init__(f'Mode {mode} is not valid.'+
                          ' Mode must be either an int within the range 1 to 4,'+
                          ' or a selection from `whspah.MODES`.')

class InvalidIntensity(ValueError):
    """
    Gets raised if the chosen intensity is not within range.
    """

    def __init__(self, intensity: int, shouldBeZero=False):
        message = f'Intensity {intensity} is not valid.'
        if shouldBeZero:
            message += ' The mode specified requires the intensity to be 0.'
        else:
            message += ' Intensity must be an int within the range 0 to 99.'
        super().__init__(message)
