//! Settings-specific package dependencies
//!
//! Dependency definitions for packages used by settings.

use crate::common::package::{Dependency, PackageDefinition, PackageManager};
use crate::common::requirements::InstallTest;

// =============================================================================
// Clipboard
// =============================================================================

pub static CLIPMENU: Dependency = Dependency {
    name: "clipmenu",
    packages: &[PackageDefinition::new("clipmenu", PackageManager::Pacman)],
    tests: &[InstallTest::WhichSucceeds("clipmenud")],
};

// =============================================================================
// Storage
// =============================================================================

pub static UDISKIE: Dependency = Dependency {
    name: "udiskie",
    packages: &[
        PackageDefinition::new("udiskie", PackageManager::Pacman),
        PackageDefinition::new("udiskie", PackageManager::Apt),
    ],
    tests: &[InstallTest::WhichSucceeds("udiskie")],
};

// =============================================================================
// Bluetooth
// =============================================================================

pub static BLUEZ: Dependency = Dependency {
    name: "BlueZ bluetooth daemon",
    packages: &[
        PackageDefinition::new("bluez", PackageManager::Pacman),
        PackageDefinition::new("bluez", PackageManager::Apt),
    ],
    tests: &[
        InstallTest::WhichSucceeds("bluetoothd"),
        InstallTest::FileExists("/usr/lib/systemd/system/bluetooth.service"),
    ],
};

pub static BLUEZ_UTILS: Dependency = Dependency {
    name: "BlueZ utilities",
    packages: &[
        PackageDefinition::new("bluez-utils", PackageManager::Pacman),
        PackageDefinition::new("bluez", PackageManager::Apt),
    ],
    tests: &[InstallTest::WhichSucceeds("bluetoothctl")],
};

// =============================================================================
// System
// =============================================================================

pub static COCKPIT: Dependency = Dependency {
    name: "Cockpit",
    packages: &[
        PackageDefinition::new("cockpit", PackageManager::Pacman),
        PackageDefinition::new("cockpit", PackageManager::Apt),
    ],
    tests: &[
        InstallTest::FileExists("/usr/lib/systemd/system/cockpit.socket"),
        InstallTest::WhichSucceeds("cockpit-bridge"),
    ],
};

pub static FASTFETCH: Dependency = Dependency {
    name: "fastfetch",
    packages: &[
        PackageDefinition::new("fastfetch", PackageManager::Pacman),
        PackageDefinition::new("fastfetch", PackageManager::Apt),
    ],
    tests: &[InstallTest::WhichSucceeds("fastfetch")],
};

pub static PACMAN_CONTRIB: Dependency = Dependency {
    name: "pacman-contrib",
    packages: &[PackageDefinition::new(
        "pacman-contrib",
        PackageManager::Pacman,
    )],
    tests: &[
        InstallTest::WhichSucceeds("paccache"),
        InstallTest::WhichSucceeds("checkupdates"),
    ],
};

pub static TOPGRADE: Dependency = Dependency {
    name: "topgrade",
    packages: &[PackageDefinition::new("topgrade", PackageManager::Pacman)],
    tests: &[InstallTest::WhichSucceeds("topgrade")],
};

pub static GNOME_FIRMWARE: Dependency = Dependency {
    name: "GNOME Firmware manager",
    packages: &[
        PackageDefinition::new("gnome-firmware", PackageManager::Pacman),
        PackageDefinition::new("gnome-firmware", PackageManager::Apt),
    ],
    tests: &[InstallTest::WhichSucceeds("gnome-firmware")],
};

pub static CHROMIUM: Dependency = Dependency {
    name: "Chromium browser",
    packages: &[
        PackageDefinition::new("chromium", PackageManager::Pacman),
        PackageDefinition::new("chromium-browser", PackageManager::Apt),
    ],
    tests: &[InstallTest::WhichSucceeds("chromium")],
};

// Cockpit requires both cockpit and chromium for the browser interface
pub static COCKPIT_DEPS: &[&Dependency] = &[&COCKPIT, &CHROMIUM];

// =============================================================================
// Default Apps (apps.rs)
// =============================================================================

pub static XDG_UTILS: Dependency = Dependency {
    name: "xdg-utils",
    packages: &[
        PackageDefinition::new("xdg-utils", PackageManager::Pacman),
        PackageDefinition::new("xdg-utils", PackageManager::Apt),
    ],
    tests: &[InstallTest::WhichSucceeds("xdg-open")],
};

// =============================================================================
// Network (network.rs)
// =============================================================================

pub static NM_CONNECTION_EDITOR: Dependency = Dependency {
    name: "Network connection editor",
    packages: &[
        PackageDefinition::new("nm-connection-editor", PackageManager::Pacman),
        PackageDefinition::new("network-manager-gnome", PackageManager::Apt),
    ],
    tests: &[InstallTest::WhichSucceeds("nm-connection-editor")],
};

pub static NMTUI: Dependency = Dependency {
    name: "Network Manager TUI",
    packages: &[
        PackageDefinition::new("networkmanager", PackageManager::Pacman),
        PackageDefinition::new("network-manager", PackageManager::Apt),
    ],
    tests: &[InstallTest::WhichSucceeds("nmtui")],
};

// =============================================================================
// Appearance (appearance.rs)
// =============================================================================

pub static YAZI: Dependency = Dependency {
    name: "Yazi file manager",
    packages: &[
        PackageDefinition::new("yazi", PackageManager::Pacman),
        PackageDefinition::new("yazi", PackageManager::Apt),
    ],
    tests: &[InstallTest::WhichSucceeds("yazi")],
};

pub static SWWW: Dependency = Dependency {
    name: "swww",
    packages: &[PackageDefinition::new("swww", PackageManager::Pacman)],
    tests: &[InstallTest::WhichSucceeds("swww")],
};

pub static ZENITY: Dependency = Dependency {
    name: "Zenity dialogs",
    packages: &[
        PackageDefinition::new("zenity", PackageManager::Pacman),
        PackageDefinition::new("zenity", PackageManager::Apt),
    ],
    tests: &[InstallTest::WhichSucceeds("zenity")],
};

// =============================================================================
// Printer (printer.rs)
// =============================================================================

pub static CUPS: Dependency = Dependency {
    name: "CUPS print server",
    packages: &[
        PackageDefinition::new("cups", PackageManager::Pacman),
        PackageDefinition::new("cups", PackageManager::Apt),
    ],
    tests: &[
        InstallTest::FileExists("/usr/bin/cupsd"),
        InstallTest::FileExists("/usr/sbin/cupsd"),
    ],
};

pub static CUPS_FILTERS: Dependency = Dependency {
    name: "cups-filters",
    packages: &[
        PackageDefinition::new("cups-filters", PackageManager::Pacman),
        PackageDefinition::new("cups-filters", PackageManager::Apt),
    ],
    tests: &[InstallTest::WhichSucceeds("cupsfilter")],
};

pub static GHOSTSCRIPT: Dependency = Dependency {
    name: "Ghostscript",
    packages: &[
        PackageDefinition::new("ghostscript", PackageManager::Pacman),
        PackageDefinition::new("ghostscript", PackageManager::Apt),
    ],
    tests: &[InstallTest::WhichSucceeds("gs")],
};

pub static AVAHI: Dependency = Dependency {
    name: "Avahi",
    packages: &[
        PackageDefinition::new("avahi", PackageManager::Pacman),
        PackageDefinition::new("avahi-daemon", PackageManager::Apt),
    ],
    tests: &[InstallTest::WhichSucceeds("avahi-daemon")],
};

pub static SYSTEM_CONFIG_PRINTER: Dependency = Dependency {
    name: "Printer configuration utility",
    packages: &[
        PackageDefinition::new("system-config-printer", PackageManager::Pacman),
        PackageDefinition::new("system-config-printer", PackageManager::Apt),
    ],
    tests: &[InstallTest::WhichSucceeds("system-config-printer")],
};

pub static NSS_MDNS: Dependency = Dependency {
    name: "nss-mdns",
    packages: &[
        PackageDefinition::new("nss-mdns", PackageManager::Pacman),
        PackageDefinition::new("libnss-mdns", PackageManager::Apt),
    ],
    tests: &[
        InstallTest::FileExists("/usr/lib/libnss_mdns.so.2"),
        InstallTest::FileExists("/usr/lib/x86_64-linux-gnu/libnss_mdns.so.2"),
    ],
};

/// All printer-related dependencies for installation
pub static PRINTER_DEPS: &[&Dependency] = &[
    &CUPS,
    &CUPS_FILTERS,
    &GHOSTSCRIPT,
    &AVAHI,
    &SYSTEM_CONFIG_PRINTER,
    &NSS_MDNS,
];

// =============================================================================
// Desktop (desktop.rs)
// =============================================================================

pub static PIPER: Dependency = Dependency {
    name: "Piper mouse configurator",
    packages: &[
        PackageDefinition::new("piper", PackageManager::Pacman),
        PackageDefinition::new("piper", PackageManager::Apt),
    ],
    tests: &[InstallTest::WhichSucceeds("piper")],
};

pub static BLUEMAN: Dependency = Dependency {
    name: "Blueman",
    packages: &[
        PackageDefinition::new("blueman", PackageManager::Pacman),
        PackageDefinition::new("blueman", PackageManager::Apt),
    ],
    tests: &[InstallTest::WhichSucceeds("blueman-manager")],
};

// =============================================================================
// Storage (storage.rs)
// =============================================================================

pub static GNOME_DISKS: Dependency = Dependency {
    name: "GNOME Disks",
    packages: &[
        PackageDefinition::new("gnome-disk-utility", PackageManager::Pacman),
        PackageDefinition::new("gnome-disk-utility", PackageManager::Apt),
    ],
    tests: &[InstallTest::WhichSucceeds("gnome-disks")],
};

pub static GPARTED: Dependency = Dependency {
    name: "GParted",
    packages: &[
        PackageDefinition::new("gparted", PackageManager::Pacman),
        PackageDefinition::new("gparted", PackageManager::Apt),
    ],
    tests: &[InstallTest::WhichSucceeds("gparted")],
};

// =============================================================================
// Audio (wiremix.rs)
// =============================================================================

pub static WIREMIX: Dependency = Dependency {
    name: "Wiremix",
    packages: &[PackageDefinition::new("wiremix", PackageManager::Pacman)],
    tests: &[InstallTest::WhichSucceeds("wiremix")],
};

// =============================================================================
// Flatpak
// =============================================================================

pub static FLATPAK: Dependency = Dependency {
    name: "Flatpak",
    packages: &[
        PackageDefinition::new("flatpak", PackageManager::Pacman),
        PackageDefinition::new("flatpak", PackageManager::Apt),
    ],
    tests: &[InstallTest::WhichSucceeds("flatpak")],
};

// =============================================================================
// AppImages
// =============================================================================

pub static GEARLEVER: Dependency = Dependency {
    name: "Gear Lever",
    packages: &[PackageDefinition::new(
        "it.mijorus.gearlever",
        PackageManager::Flatpak,
    )],
    tests: &[InstallTest::CommandSucceeds {
        program: "flatpak",
        args: &["info", "it.mijorus.gearlever"],
    }],
};
