<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Product Id="*" 
             Name="Scar Chat" 
             Language="1033" 
             Version="1.0.0" 
             Manufacturer="SCAR" 
             UpgradeCode="PUT-GUID-HERE">
        
        <Package InstallerVersion="200" 
                 Compressed="yes" 
                 InstallScope="perMachine" 
                 Description="SCAR Chat Installer" 
                 Comments="Cross-platform secure chat application" />

        <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
        <MediaTemplate EmbedCab="yes" />

        <Feature Id="ProductFeature" Title="Scar Chat" Level="1">
            <ComponentGroupRef Id="ProductComponents" />
            <ComponentRef Id="ApplicationShortcut" />
        </Feature>

        <!-- UI -->
        <UIRef Id="WixUI_InstallDir" />
        <Property Id="WIXUI_INSTALLDIR" Value="INSTALLFOLDER" />

        <!-- Icon -->
        <!-- TODO: Add application icon -->
        <!-- <Icon Id="AppIcon" SourceFile="$(var.SourceDir)\app_icon.ico" /> -->
        <!-- <Property Id="ARPPRODUCTICON" Value="AppIcon" /> -->
    </Product>

    <Fragment>
        <Directory Id="TARGETDIR" Name="SourceDir">
            <Directory Id="ProgramFilesFolder">
                <Directory Id="INSTALLFOLDER" Name="Scar Chat" />
            </Directory>
            
            <Directory Id="ProgramMenuFolder">
                <Directory Id="ApplicationProgramsFolder" Name="Scar Chat" />
            </Directory>
        </Directory>
    </Fragment>

    <Fragment>
        <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
            <!-- Main executable -->
            <Component Id="ClientExecutable" Guid="PUT-GUID-HERE">
                <File Id="scarChatExe" 
                      Source="$(var.BuildDir)\scarchat.exe" 
                      KeyPath="yes" 
                      Checksum="yes" />
            </Component>

            <!-- Qt6 DLLs -->
            <Component Id="Qt6Core" Guid="PUT-GUID-HERE">
                <File Id="Qt6CoreDll" Source="$(var.Qt6Dir)\bin\Qt6Core.dll" />
            </Component>
            
            <Component Id="Qt6Gui" Guid="PUT-GUID-HERE">
                <File Id="Qt6GuiDll" Source="$(var.Qt6Dir)\bin\Qt6Gui.dll" />
            </Component>
            
            <Component Id="Qt6Widgets" Guid="PUT-GUID-HERE">
                <File Id="Qt6WidgetsDll" Source="$(var.Qt6Dir)\bin\Qt6Widgets.dll" />
            </Component>

            <Component Id="Qt6Network" Guid="PUT-GUID-HERE">
                <File Id="Qt6NetworkDll" Source="$(var.Qt6Dir)\bin\Qt6Network.dll" />
            </Component>

            <Component Id="Qt6Sql" Guid="PUT-GUID-HERE">
                <File Id="Qt6SqlDll" Source="$(var.Qt6Dir)\bin\Qt6Sql.dll" />
            </Component>

            <!-- Boost DLLs (if dynamically linked) -->
            <!-- <Component Id="BoostSystem" Guid="PUT-GUID-HERE">
                <File Id="BoostSystemDll" Source="$(var.BoostDir)\lib\boost_system.dll" />
            </Component> -->

            <!-- OpenSSL DLLs -->
            <Component Id="OpenSSL" Guid="PUT-GUID-HERE">
                <File Id="LibCryptoDll" Source="$(var.OpenSSLDir)\bin\libcrypto-3-x64.dll" />
                <File Id="LibSslDll" Source="$(var.OpenSSLDir)\bin\libssl-3-x64.dll" />
            </Component>

            <!-- SQLite DLL (if not statically linked) -->
            <!-- <Component Id="SQLite3" Guid="PUT-GUID-HERE">
                <File Id="Sqlite3Dll" Source="$(var.SQLiteDir)\sqlite3.dll" />
            </Component> -->

            <!-- FFmpeg DLLs for video/screen capture -->
            <Component Id="FFmpeg" Guid="PUT-GUID-HERE">
                <File Id="AvCodecDll" Source="$(var.FFmpegDir)\bin\avcodec-60.dll" />
                <File Id="AvFormatDll" Source="$(var.FFmpegDir)\bin\avformat-60.dll" />
                <File Id="AvUtilDll" Source="$(var.FFmpegDir)\bin\avutil-58.dll" />
            </Component>

            <!-- README and documentation -->
            <Component Id="Documentation" Guid="PUT-GUID-HERE">
                <File Id="ReadmeTxt" Source="$(var.SourceDir)\README.md" />
            </Component>
        </ComponentGroup>

        <!-- Start Menu Shortcut -->
        <DirectoryRef Id="ApplicationProgramsFolder">
            <Component Id="ApplicationShortcut" Guid="PUT-GUID-HERE">
                <Shortcut Id="ApplicationStartMenuShortcut"
                          Name="Scar Chat"
                          Description="Secure chat application with video streaming"
                          Target="[INSTALLFOLDER]scarchat.exe"
                          WorkingDirectory="INSTALLFOLDER" />
                
                <RemoveFolder Id="CleanUpShortCut" Directory="ApplicationProgramsFolder" On="uninstall" />
                <RegistryValue Root="HKCU" 
                               Key="Software\SCAR\Scar Chat" 
                               Name="installed" 
                               Type="integer" 
                               Value="1" 
                               KeyPath="yes" />
            </Component>
        </DirectoryRef>
    </Fragment>
</Wix>
