#include "evse_state.h"

static evse_state_t current_state = EVSE_STATE_A;

void evse_set_state(evse_state_t state) {
    current_state = state;
}

evse_state_t evse_get_state(void) {
    return current_state;
}

const char* evse_state_to_str(evse_state_t state) {
    switch (state) {
        case EVSE_STATE_A:  return "A - EV Not Connected (12V)";
        case EVSE_STATE_B1: return "B1 - EV Connected (9V, Not Authorized)";
        case EVSE_STATE_B2: return "B2 - EV Connected (9V, Authorized and Ready)";
        case EVSE_STATE_C1: return "C1 - Charging Requested (6V, Relay Off)";
        case EVSE_STATE_C2: return "C2 - Charging Active (6V, Relay On)";
        case EVSE_STATE_D1: return "D1 - Ventilation Required (3V, Relay Off)";
        case EVSE_STATE_D2: return "D2 - Ventilation Active (3V, Relay On)";
        case EVSE_STATE_E:  return "E - Error: Control Pilot Shorted to Ground (0V)";
        case EVSE_STATE_F:  return "F - Fault: EVSE Unavailable or No Pilot Signal";
        default:            return "Unknown State";
    }
}

void evse_state_init(void) {
    // Inicialização do estado EVSE
}


void evse_state_tick(void) {
    // Tick do estado (placeholder)
}

bool evse_state_is_charging(evse_state_t state) {
    return state == EVSE_STATE_C1 || state == EVSE_STATE_C2;
}

bool evse_state_is_plugged(evse_state_t state) {
    return state == EVSE_STATE_B1 || state == EVSE_STATE_B2 ||
           state == EVSE_STATE_C1 || state == EVSE_STATE_C2 ||
           state == EVSE_STATE_D1 || state == EVSE_STATE_D2;
}

bool evse_state_is_session(evse_state_t state) {
    return state == EVSE_STATE_B2 || state == EVSE_STATE_C1 || state == EVSE_STATE_C2;
}
