from alarm import BaseAlarmClock, AlarmState
from datetime import time, datetime
from time import sleep
from pynput import keyboard

# Simple Alarm Clock has 5 functionalities:
# 1. Set Alarm Time - Set the time for the alarm to sound, does NOT make the alarm active
# 2. Start Alarm    - Make the alarm active, which will run the timer until it reaches the specified time
# 3. Sound Alarm    - Play the sound for the alarm
# 4. Snooze Alarm   - Stop the alarm sound and wait for some time to play the alarm again
# 5. Stop Alarm     - If the alarm is active or is playing, stop the alarm (deactivate state)

ALARM_TIME = time(19, 13, 0)
SNOOZE_KEY = keyboard.Key.up
ALARM_OFF_KEY = keyboard.Key.esc
SNOOZE_SEC = 5


def simple_alarm_mode(alarm_clock: BaseAlarmClock):
    alarm_clock.start_alarm()
    while not alarm_clock.alarm_check_reached():
        print(f"ALARM SLEEPING @: {datetime.now().time()}")
        sleep(1)
    alarm_clock.sound_alarm()
    while alarm_clock.current_state is not AlarmState.DEACTIVATED:
        with keyboard.Events() as events:
            for event in events:
                if event.key == ALARM_OFF_KEY:
                    alarm_clock.stop_alarm()
                    break
                elif event.key == SNOOZE_KEY:
                    alarm_clock.snooze_alarm()
                    sleep(SNOOZE_SEC)
                    alarm_clock.sound_alarm()
                    break


if __name__ == '__main__':
    alarm_clock = BaseAlarmClock(ALARM_TIME)
    simple_alarm_mode(alarm_clock)