// NIP Configuration with USE Flags - Valid KDL Format
// This demonstrates proper KDL syntax for NIP configuration

nip {
    // Basic Directory Configuration
    programs-dir "/Programs"
    links-dir "/System/Links"
    cache-dir "/var/nip/cache"
    db-file "/var/nip/db/packages.json"

    // Global Options
    auto-symlink true
    check-conflicts true
    verbose false

    // Global USE Flags
    // In valid KDL, flags are represented as nodes with properties
    use-flags {
        // Init System
        init {
            systemd enabled=false
            dinit enabled=true
            openrc enabled=false
            runit enabled=false
        }

        // GUI Toolkit
        gui {
            X enabled=false
            wayland enabled=true
            gtk enabled=true
            qt enabled=false
        }

        // Audio System
        audio {
            pulseaudio enabled=false
            pipewire enabled=true
            alsa enabled=true
        }

        // Optimization
        optimization {
            lto enabled=true
            pgo enabled=true
            debug enabled=false
            strip enabled=true
        }

        // Security
        security {
            hardened enabled=true
            pie enabled=true
            relro enabled=true
            stack-protector enabled=true
        }

        // Common Features
        features {
            ipv6 enabled=true
            ssl enabled=true
            zstd enabled=true
            lz4 enabled=true
            doc enabled=false
            examples enabled=false
            dbus enabled=true
        }
    }

    // Compiler Flags
    compiler {
        CFLAGS "-O3 -march=native -pipe"
        CXXFLAGS "-O3 -march=native -pipe"
        LDFLAGS "-Wl,-O1 -Wl,--as-needed"
        MAKEFLAGS "-j8"
        RUSTFLAGS "-C opt-level=3 -C target-cpu=native"
    }

    // Build Profiles
    profiles {
        active "performance"

        profile "minimal" {
            description "Minimal features for embedded systems"
            base "default"

            use-flags {
                systemd enabled=false
                X enabled=false
                wayland enabled=false
                doc enabled=false
                ssl enabled=true
                ipv6 enabled=true
            }

            compiler {
                CFLAGS "-Os -pipe"
                CXXFLAGS "-Os -pipe"
                LDFLAGS "-Wl,-O1 -Wl,--as-needed"
                MAKEFLAGS "-j4"
            }
        }

        profile "performance" {
            description "Maximum performance optimizations"
            base "default"

            use-flags {
                lto enabled=true
                pgo enabled=true
                debug enabled=false
                strip enabled=true
            }

            compiler {
                CFLAGS "-O3 -march=native -flto -pipe"
                CXXFLAGS "-O3 -march=native -flto -pipe"
                LDFLAGS "-Wl,-O1 -flto"
                MAKEFLAGS "-j16"
            }
        }

        profile "desktop" {
            description "Full desktop environment"
            base "default"

            use-flags {
                dinit enabled=true
                wayland enabled=true
                gtk enabled=true
                pipewire enabled=true
                dbus enabled=true
            }

            compiler {
                CFLAGS "-O2 -pipe"
                CXXFLAGS "-O2 -pipe"
                LDFLAGS "-Wl,-O1"
                MAKEFLAGS "-j8"
            }
        }
    }

    // Per-Package Configuration
    package "firefox" {
        description "Firefox web browser"

        use-flags {
            wayland enabled=true
            X enabled=false
            alsa enabled=true
            pulseaudio enabled=false
            lto enabled=true
        }

        compiler {
            CFLAGS "-O3 -march=native -flto"
            CXXFLAGS "-O3 -march=native -flto"
            MAKEFLAGS "-j8"
        }
    }

    package "nginx" {
        description "Nginx web server"

        use-flags {
            ssl enabled=true
            http2 enabled=true
            http3 enabled=true
            zstd enabled=true
            hardened enabled=true
        }

        compiler {
            CFLAGS "-O3 -flto -fstack-protector-strong"
            LDFLAGS "-Wl,-O1 -Wl,-z,relro -Wl,-z,now"
        }
    }

    package "python" {
        description "Python interpreter"

        use-flags {
            lto enabled=true
            pgo enabled=true
            ssl enabled=true
            ipv6 enabled=true
        }

        compiler {
            CFLAGS "-O3 -march=native -flto"
            LDFLAGS "-Wl,-O1 -flto"
        }
    }

    // Adapter Configuration
    adapters {
        nix {
            enabled true
            priority 10
        }

        pkgsrc {
            enabled true
            priority 20
            build-from-source true
        }

        pacman {
            enabled true
            priority 30
        }
    }
}
