#pragma once

#ifdef ESP_PLATFORM
#include "mcp2521_hardware_handle.hpp"
#include "mcp2521_hardware_esp_bus.hpp"

#include "driver/gpio.h"
#include "driver/spi_master.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"

class MCP2521_HardwareHandleFactory_ESPBus {
private:
    spi_bus_config_t bus_config;
    spi_host_device_t spi_host;

    gpio_num_t mosi; 
    gpio_num_t miso;
    gpio_num_t sclk;

    QueueHandle_t spi_queue;
    TaskHandle_t transactionTaskHandle;

public:
    MCP2521_HardwareHandleFactory_ESPBus(
        spi_host_device_t spi_host,
        gpio_num_t mosi, 
        gpio_num_t miso, 
        gpio_num_t sclk
    );

    void transactionTaskFn();

    MCP2521_HardwareHandle_ESPBus create(
        gpio_num_t int_pin,
        gpio_num_t cs
    );
};

#endif