#pragma once

#include <Windows.h>

#include <string_view>

#include "adapters/windows/diagnostics/WindowsConsoleLogSink.h"

namespace ta::adapters::windows::console
{
    class WindowsConsoleSession final
    {
    public:
        WindowsConsoleSession() noexcept = default;
        ~WindowsConsoleSession() noexcept;

        WindowsConsoleSession(const WindowsConsoleSession&) = delete;
        WindowsConsoleSession& operator=(const WindowsConsoleSession&) = delete;

        [[nodiscard]] bool open(std::string_view title) noexcept;
        void close() noexcept;
        [[nodiscard]] bool is_open() const noexcept { return open_; }

    private:
        HANDLE output_ = nullptr;
        HANDLE original_stdin_ = nullptr;
        HANDLE original_stdout_ = nullptr;
        HANDLE original_stderr_ = nullptr;
        diagnostics::WindowsConsoleLogSink sink_;
        bool open_ = false;
    };
}
