#pragma once

#include <string>
#include <initializer_list>
#include <vector>

namespace Ksword::Features::Network {

// NetworkAuditPageId identifies one read-only Network audit tab. Inputs come
// from the tab item payload; processing uses the enum to select table columns
// and rows; it owns no external resource.
enum class NetworkAuditPageId {
    TcpUdpCrossView,
    AfdEndpoint,
    WfpInventory,
    NdisChain,
    NsiSummary
};

// NetworkAuditColumn describes one report-mode column. Inputs are static page
// metadata; processing in NetworkView maps them to ListView columns; output is
// visual-only and never changes R0 state.
struct NetworkAuditColumn {
    int width = 120;
    int format = 0;
    std::wstring title;
};

// NetworkAuditRow is one display row in a Network audit table. Inputs are
// ArkDriverClient-derived values or explicit unsupported diagnostics; processing
// only renders cell text; return behavior is value-only.
struct NetworkAuditRow {
    std::vector<std::wstring> cells;
};

// NetworkAuditPage describes one tab, its columns, and its initial read-only
// rows. Inputs are generated by BuildNetworkAuditPages; NetworkView consumes the
// descriptors without mutating them.
struct NetworkAuditPage {
    NetworkAuditPageId id = NetworkAuditPageId::TcpUdpCrossView;
    std::wstring title;
    std::wstring summary;
    std::vector<NetworkAuditColumn> columns;
    std::vector<NetworkAuditRow> rows;
};

// NetworkAuditModel owns the ARKLight Network audit snapshot. Inputs are none;
// processing prepares stable tab descriptors and refreshes rows through
// ArkDriverClient wrappers where available; output is const accessors for the
// Win32 view.
class NetworkAuditModel final {
public:
    NetworkAuditModel();

    // refresh 重新采集 ArkDriverClient 网络审计快照。
    // 输入：无；处理：重建所有 NetworkAuditPage 行数据；返回：无返回值。
    void refresh();

    // replacePages installs a complete immutable audit snapshot collected by a
    // background task. It does not perform I/O on the calling UI thread.
    void replacePages(std::vector<NetworkAuditPage> pages);

    // pages returns the immutable page descriptors. There is no input; output
    // remains valid for the lifetime of this model instance.
    const std::vector<NetworkAuditPage>& pages() const noexcept;

    // pageAt validates a tab index. Input is a zero-based tab index; output is
    // nullptr when the index is outside the current descriptor list.
    const NetworkAuditPage* pageAt(int index) const noexcept;

private:
    std::vector<NetworkAuditPage> pages_;
};

// BuildNetworkAuditPages creates the complete initial Network tab set. Inputs
// are none; processing stays local and read-only; output is copied into the
// model.
std::vector<NetworkAuditPage> BuildNetworkAuditPages();

} // namespace Ksword::Features::Network
