#pragma once

#include "IBaseClash.h"
#include <yaml-cpp/yaml.h>
#include "CTool.h"
#include "CProcess.h"
#include "Logger.h"
 

class CLashConfig : public IBaseClash
{
public:
	CLashConfig();
	~CLashConfig(void);

	// 通过 IBaseClash 继承
	virtual BOOL MakeClash() override;

	virtual BOOL InitClash() override;


	// 通过 IBaseClash 继承
	virtual BOOL StartClash() override;

	virtual BOOL StopClash() override;
	virtual int GetHttpPort() override;
	virtual int GetSocketPort() override;
	virtual int GetClasApiPort() override;

public:
 
	std::filesystem::path GetRunConfig();
	void SetProxy();
private:
	YAML::Node buildShadowsocks(CServerListMode* node);
	YAML::Node buildtrojan(CServerListMode* node);
	YAML::Node buildv2ray(CServerListMode* node);
	std::vector<YAML::Node> buildv2rayHost(CServerListMode* node);

	YAML::Node builTunConfig();
	YAML::Node buildDnsConfig();
	std::vector<YAML::Node> buildProxyGroups();
	std::vector<YAML::Node> buildRules();
	std::vector<YAML::Node> buildruleproviders();
private:
	void ThreadFun_process_Config(LPARAM lParam);
	void ThreadFun_ProcessMonitor_Config(LPARAM lParam);
	
	/*winrt::fire_and_forget _StartClash();
	winrt::Windows::Foundation::IAsyncAction ProcessMonitor();*/
private:
	int m_socks_port;
	int m_http_port;
	int m_c_port;
	bool   m_is_qut;
	CProcess* m_process;
	AsynTaskHandle<LPARAM>	m_Asyntask;
	AsynTaskHandle<LPARAM>	m_AsyntaskProcessMonitor;
	std::vector<std::string> m_rules;
 
	std::filesystem::path m_run_config;
	
};

