#pragma once

#include <stdbool.h>
#include <stdint.h>

#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <lvgl.h>
#include <tt_app.h>

typedef struct {
    volatile bool running;
    volatile bool http_ready;
    volatile bool http_exited;
    volatile bool discovery_ready;
    volatile bool visible;
    volatile bool override_active;

    int http_socket;
    int client_socket;
    int discovery_socket;
    TaskHandle_t http_task;
    TaskHandle_t discovery_task;

    AppHandle app;
    lv_obj_t* draw_area;
    lv_obj_t* server_label;
    lv_obj_t* tool_label;

    uint16_t* framebuffer;
    size_t framebuffer_size;
    uint16_t display_width;
    uint16_t display_height;
    uint16_t draw_width;
    uint16_t draw_height;
    int draw_color;
} McpScreenState;

bool mcp_services_start(McpScreenState* state);
void mcp_services_hide(McpScreenState* state);
void mcp_services_stop(McpScreenState* state);

void mcp_ui_set_server_status(McpScreenState* state, const char* status);
void mcp_ui_set_last_tool(McpScreenState* state, const char* tool);
bool mcp_ui_clear(McpScreenState* state, int color);
bool mcp_ui_draw_text(
    McpScreenState* state,
    const char* text,
    int x,
    int y,
    int size
);
bool mcp_ui_draw_rgb565_be(
    McpScreenState* state,
    const uint8_t* data,
    size_t data_size,
    int x,
    int y,
    int width,
    int height
);
bool mcp_ui_draw_bmp(
    McpScreenState* state,
    const uint8_t* data,
    size_t data_size,
    int x,
    int y
);
bool mcp_ui_draw_pbm(
    McpScreenState* state,
    const uint8_t* data,
    size_t data_size,
    int x,
    int y
);
char* mcp_ui_get_screenshot_pbm_base64(McpScreenState* state);
