#pragma once
#include <windows.h>
#include <string>

struct AppSettings {
    int  captureId = 0;
    std::wstring modelFile;
    bool pinned = true, autoPaste = true, autoHide = false;
    int  winX = CW_USEDEFAULT, winY = CW_USEDEFAULT, winW = 400, winH = 340;
    int  hkMods = MOD_CONTROL | MOD_SHIFT;
    int  hkVk   = VK_SPACE;
};

inline std::wstring SettingsPath() {
    wchar_t buf[MAX_PATH]; GetModuleFileNameW(nullptr, buf, MAX_PATH);
    std::wstring p(buf); p = p.substr(0, p.find_last_of(L"\\/"));
    return p + L"\\win-dictation.ini";
}

inline int  GetIni(const wchar_t* k, int d) { return GetPrivateProfileIntW(L"app", k, d, SettingsPath().c_str()); }
inline void PutIni(const wchar_t* k, int v) { wchar_t b[32]; wsprintfW(b, L"%d", v); WritePrivateProfileStringW(L"app", k, b, SettingsPath().c_str()); }

inline void LoadSettings(AppSettings& s) {
    s.captureId = GetIni(L"captureId", s.captureId);
    s.pinned    = GetIni(L"pinned",    s.pinned)    != 0;
    s.autoPaste = GetIni(L"autoPaste", s.autoPaste) != 0;
    s.autoHide  = GetIni(L"autoHide",  s.autoHide)  != 0;
    s.winX = GetIni(L"winX", s.winX); s.winY = GetIni(L"winY", s.winY);
    s.winW = GetIni(L"winW", s.winW); s.winH = GetIni(L"winH", s.winH);
    s.hkMods = GetIni(L"hkMods", s.hkMods);
    s.hkVk   = GetIni(L"hkVk",   s.hkVk);
    wchar_t m[MAX_PATH]; GetPrivateProfileStringW(L"app", L"modelFile", L"", m, MAX_PATH, SettingsPath().c_str());
    s.modelFile = m;
}

inline void SaveSettings(const AppSettings& s) {
    PutIni(L"captureId", s.captureId); PutIni(L"pinned", s.pinned);
    PutIni(L"autoPaste", s.autoPaste); PutIni(L"autoHide", s.autoHide);
    PutIni(L"winX", s.winX); PutIni(L"winY", s.winY); PutIni(L"winW", s.winW); PutIni(L"winH", s.winH);
    PutIni(L"hkMods", s.hkMods); PutIni(L"hkVk", s.hkVk);
    WritePrivateProfileStringW(L"app", L"modelFile", s.modelFile.c_str(), SettingsPath().c_str());
}
