#include "core/process_state_machine.h"

namespace fn_ui {

ProcessState process_transition(ProcessState s, ProcessEvent e) {
    using S = ProcessState;
    using E = ProcessEvent;
    switch (s) {
    case S::Idle:
        // Trigger es una solicitud, el cambio real ocurre con Spawned.
        if (e == E::Spawned) return S::Running;
        return s;
    case S::Running:
        if (e == E::Finished)             return S::Success;
        if (e == E::Failed || e == E::Timeout) return S::Error;
        return s;
    case S::Success:
    case S::Error:
        if (e == E::Reset) return S::Idle;
        return s;
    }
    return s;
}

const char* process_state_name(ProcessState s) {
    switch (s) {
    case ProcessState::Idle:    return "Idle";
    case ProcessState::Running: return "Running";
    case ProcessState::Success: return "Success";
    case ProcessState::Error:   return "Error";
    }
    return "Unknown";
}

const char* process_event_name(ProcessEvent e) {
    switch (e) {
    case ProcessEvent::Trigger:  return "Trigger";
    case ProcessEvent::Spawned:  return "Spawned";
    case ProcessEvent::Finished: return "Finished";
    case ProcessEvent::Failed:   return "Failed";
    case ProcessEvent::Timeout:  return "Timeout";
    case ProcessEvent::Reset:    return "Reset";
    }
    return "Unknown";
}

} // namespace fn_ui
