#ifndef _LED_STRIP_H
#define _LED_STRIP_H

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "common/LEDStrip.h"
#include <ArduinoJson.h>
#include "my_board.h"

extern LEDSTRIP *strip1;
extern LEDSTRIP *strip2;
extern TaskHandle_t Strip1_Task_Handle;
extern TaskHandle_t Strip2_Task_Handle;
extern TaskHandle_t FrontLight_Task_Handle;

#define ANIM_WHITEFILL_INDEX 0
#define ANIM_DEFAULT_INDEX 1
#define ANIM_EVENT_SIZE 12
#define PROFILES_SIZE 8

#define MIN_LED_UPDATE_INTERVAL 13

enum OtherANIMS { OA_SET_PIXEL=100, OA_CLEAR, };

enum FRONT_LIGHT_STYLE { FRONT_LIKE_LUMIA, FRONT_LIKE_ROAMER };

enum EVENT_TYPE { EV_NORMAL, EV_INJECT, EV_NON_INJECT, EV_TEST,};

// Single web page event (upto 8)
typedef struct{
  EVENT_TYPE type;
  int selfIndex;
  int animIndex;
  int hue;
  int hueRange;
  int speed;
  int param1;
  int param2;
  bool check1;
  bool check2;
  bool check3;
  bool check4;
  int countDown;
}ANIMATION_EVENT;

typedef struct{
  bool enabled;
  uint8_t relayIndex;
  uint8_t core;
  int holdTime;
  int rampTime;
  float minDuty;
  float maxDuty;
  FRONT_LIGHT_STYLE style;
  //float delayFactor;
}FRONT_LIGHT;

typedef struct{
  bool enabled;
  uint8_t relayIndex;
  uint8_t buttonIndex;
  uint8_t core;
  int rampTime;
  uint8_t rampSteps;
  float min;
  float max;
}REAR_LIGHT;


typedef struct { 
  EVENT_TYPE type;
  ANIMATION_EVENT event;  
}EVENT_MSG;

// Properties from webpage
typedef struct {
  int profileIndex;
  const char* profileName;
  int whitefillsCount;
  int animationsCount;
  FRONT_LIGHT frontLight;
  REAR_LIGHT rearLight;
  ANIMATION_EVENT event[ANIM_EVENT_SIZE];
}ANIMATION_PROPS;

extern ANIMATION_PROPS animProps;

enum POPUP_ANIM { POP_STATUP, POP_BLE_CONN, POP_BLE_DISC, POP_WIFI_CONN, POP_WIFI_DISC, POP_STICK_CONN, POP_STICK_DISC };

void RunWhitefillAnimation(ANIMATION_EVENT &event);

void RunAnimation(ANIMATION_EVENT &event);

void RunPopUpAnimations(ANIMATION_EVENT &event);

//void SetEventIndex(int index, int countdown=0, bool test=false);

//void PostNewEvent( int countDown, EVENT_TYPE type, ANIMATION_EVENT &animEvent);
void PostNewEvent( ANIMATION_EVENT &animEvent);

int IncrementEventIndex(void);

void PostLastNormalEvent(void);

void load_animation_profile(void); // cfg/anim-profiles.json
void load_animation_profileByIndex(int); // cfg/anim-profileX.json 

void Init_LED_Devices(BOARD_PINS); // cfg/led-devices.json

rgbpixel_t hexToRGB(const char* hexColor);

//void Init_LEDStrip2(void);

void Init_FrontLight(void);

//void Init_RearLight(void);

void Strip1_Control_Task(void *parameters);

void Strip2_Control_Task(void *parameters);

void FrontLight_Task(void *parameters);





#endif
