import numpy as np
import slider as sl
from datetime import timedelta

QUARTER = 1
HALF = 2
NOTE = 4

def beatify(bpm:float, offset:int, time_ms:timedelta) -> float:
    return bpm/60000 * (time_ms - offset)

def debeatify(bpm:float, offset:int, beat:int) -> timedelta:
    return timedelta(milliseconds=(beat*60000/bpm) + offset)

def f(intensity): return np.pi/2 - np.arctan(2*intensity - 5)

def greedy(bpm:int, offset:int, timings:list, amplitudes:list):
    """
    input: takes Alexandre's note selection / intensity data
    output: list of object type / position
    """
    flow = 1
    notes = [sl.HitObject(0, timedelta(milliseconds=0), 0) * len(timings)]
    beats = np.array(beatify(timings))
    for (delta, note_beat, intensity, i) in zip(timings, beats, amplitudes, range(len(timings))):
        try:
            duration = note_beat - beats[i + 1]
            if duration in (QUARTER, HALF):
                notes[i] = sl.Circle(sl.Position(0, 0), delta, 0)
            notes[i] = sl.Circle(sl.Position(0, 0), delta, 0)
            """
            elif duration % 2 == 0:
                rhythms.insert(0, f"slider {duration}")
            else:
                rhythms.insert(0, f"reverse_slider {duration}")
        """
        except IndexError:
            notes[i] = sl.Circle(sl.Position(0, 0), delta, 0)
        # TODO mettre à jour flow
        """
        if len(notes) > 2:
            angle = flow * f(rhythm.intensite)
            x1, y1 = notes[i-2].position
            x2, y2 = notes[i-1].position
            old_angle = np.arctan2((y1, y2), (x1, x2))
            x3 = x2 + (intensity * np.cos(angle + old_angle))
            y3 = y2 + (intensity * np.sin(angle + old_angle))
        else:
            pass
        """
    return notes
        

        

