<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<installer-gui-script minSpecVersion="2">
    <title>Alpaca</title>
    <!-- Product identification -->
    <product id="au.com.m-square.SecureDNS2" version="1.0.0"/>
    <!-- OS Version Requirements - macOS 15.0 (Sequoia) minimum -->
    <volume-check script="volumeCheck()">
        <allowed-os-versions>
            <os-version min="15.0"/>
        </allowed-os-versions>
    </volume-check>
    <!-- Installation check for system requirements -->
    <installation-check script="installationCheck()"/>
    <!-- System requirements check (macOS version) -->
    <system-check script="systemCheck()"/>
    <!-- Installer screens -->
    <welcome file="welcome.html" mime-type="text/html"/>
    <readme file="readme.html" mime-type="text/html"/>
    <license file="license.html" mime-type="text/html"/>
    <conclusion file="conclusion.html" mime-type="text/html"/>
    <!-- Background image -->
    <background file="background.png" mime-type="image/png" alignment="bottomleft" scaling="proportional"/>
    <background-darkAqua file="background.png" mime-type="image/png" alignment="bottomleft" scaling="proportional"/>
    <!-- Installation domains - System only (required for System Extension) -->
    <domains enable_anywhere="false" enable_currentUserHome="false" enable_localSystem="true"/>
    <!-- Options - Universal binary (Apple Silicon + Intel), root volume only (no destination selection) -->
    <options customize="never" require-scripts="true" hostArchitectures="arm64,x86_64" rootVolumeOnly="true"/>
    <!-- JavaScript for checks -->
    <script><![CDATA[
    function volumeCheck() {
        // Ensure installing on boot volume for System Extension support
        if (my.target.mountpoint !== '/') {
            my.result.type = 'Fatal';
            my.result.message = 'Alpaca must be installed on the boot volume to enable System Extension functionality.';
            return false;
        }
        return true;
    }

    function systemCheck() {
        // Log architecture for diagnostics
        var arch = system.sysctl('hw.machine');
        system.log('Detected architecture: ' + arch);

        // Check macOS version (backup check - os-version min should catch this first)
        var osVersion = system.version.ProductVersion;
        system.log('Detected macOS version: ' + osVersion);

        var versionParts = osVersion.split('.');
        var majorVersion = parseInt(versionParts[0], 10);

        if (majorVersion < 15) {
            my.result.type = 'Fatal';
            my.result.title = 'macOS 15.0 or Later Required';
            my.result.message = 'Alpaca requires macOS 15.0 (Sequoia) or later.\n\nYour Mac is running macOS ' + osVersion + '.\n\nPlease update your Mac to continue.';
            return false;
        }

        return true;
    }

    function installationCheck() {
        // Check for existing installation
        var existingApp = system.files.fileExistsAtPath('/Applications/Alpaca.app');
        if (existingApp) {
            // Will upgrade existing installation
            system.log('Existing installation found - will upgrade');
        }
        return true;
    }
    ]]></script>
    <!-- Installation choices -->
    <choices-outline>
        <line choice="default"/>
    </choices-outline>
    <choice id="default" title="Alpaca" description="Install Alpaca DNS filtering application with System Extension." visible="false">
        <pkg-ref id="au.com.m-square.SecureDNS2.pkg"/>
    </choice>
    <!-- Package reference -->
    <pkg-ref id="au.com.m-square.SecureDNS2.pkg">
        <bundle-version>
            <bundle CFBundleShortVersionString="1.15.0" CFBundleVersion="620" id="au.com.m-square.SecureDNS2" path="Alpaca.app"/>
        </bundle-version>
    </pkg-ref>
    <pkg-ref id="au.com.m-square.SecureDNS2.pkg" version="1.15.0" onConclusion="none" installKBytes="24231" updateKBytes="0">#SecureDNS-component.pkg</pkg-ref>
</installer-gui-script>