import numpy as np
from datetime import datetime
from enum import Enum



class WaveformType(Enum):
    Analog = 0
    Digital = 1





class AnalogWaveform:
    def __init__(self, y, dt, name):
        """
        Creates an analog waveform.
        Args:
            y (1D list or np.ndarray()): Array of floats
            dt (float): dt (float): sampling time in seconds
            name (str): name of the waveform
        """
        self.name = name
        self.dt = dt
        self.start_time = datetime.now()
        y = np.array(y)
        y = np.concatenate([[0], y])
        self.y = y
        self.t = np.array([i * dt for i in range(len(y))])

    def get_timeseries(self):
        return self.t, self.y
    



class DigitalWaveform:
    def __init__(self, data, dt, t0=None, line_names=None):
        """
        Creates a  digital waveform.
        Args:
            data (2D list or np.ndarray): Array of 0 and/or 1
            dt (float): sampling time in seconds
            t0 (datetime, optional): initial time. If None, datetime.now() is used
            line_names (list, optional): digital channels' names.
        """
        self.data = np.array(data, dtype=int)
        self.dt = dt
        self.t0 = t0 if t0 else datetime.now()
        self.line_names = line_names if line_names else [f"Line {i}" for i in range(self.data.shape[0])]
        
        if self.data.ndim != 2:
            raise Exception("Data must be a 2D array (num_lines, num_samples)")




class AnalogType(Enum):
    Sine = 0
    Triangle = 1
    Square = 2
    Gaussian = 3
    Sinc = 4
    Lorentz = 5
    Exp_Rise = 6
    Exp_Decay = 7
    Haversine = 8




class DigitalType(Enum):
    Counter = 0
    Random = 1
    FixedDecimalValue = 2
    ArbitraryPattern = 3