#![allow(dead_code)]

use crate::error::AppResult;
use serde::{Deserialize, Serialize};

#[cfg(target_os = "macos")]
mod macos;
#[cfg(target_os = "windows")]
mod windows;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum Platform {
    MacOS,
    Windows,
    Linux,
    Unknown,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PlatformInfo {
    pub platform: Platform,
    pub version: String,
    pub supports_ios_supervision: bool,
}

#[tauri::command]
pub fn get_platform() -> AppResult<PlatformInfo> {
    #[cfg(target_os = "macos")]
    return macos::get_platform_info();

    #[cfg(target_os = "windows")]
    return windows::get_platform_info();

    #[cfg(not(any(target_os = "macos", target_os = "windows")))]
    Ok(PlatformInfo {
        platform: Platform::Unknown,
        version: String::new(),
        supports_ios_supervision: false,
    })
}

pub trait PlatformInterface {
    fn install_dns_profile(&self, profile_path: &str) -> AppResult<()>;
    fn store_token(&self, token: &str) -> AppResult<()>;
    fn read_token(&self) -> AppResult<Option<String>>;
    fn activate_protection(&self, token: &str) -> AppResult<()>;
    fn deactivate_protection(&self, token: &str) -> AppResult<()>;
}

pub fn activate_protection(profile_or_token: &str) -> AppResult<()> {
    #[cfg(target_os = "macos")]
    return macos::activate_protection(profile_or_token);

    #[cfg(target_os = "windows")]
    return windows::activate_protection(profile_or_token);

    #[cfg(not(any(target_os = "macos", target_os = "windows")))]
    Err(crate::error::AppError::new(
        "Plattform wird nicht unterstützt".to_string(),
    ))
}

pub fn get_hardware_id() -> AppResult<String> {
    #[cfg(target_os = "macos")]
    return macos::get_hardware_id();

    #[cfg(target_os = "windows")]
    return windows::get_hardware_id();

    #[cfg(not(any(target_os = "macos", target_os = "windows")))]
    Err(crate::error::AppError::new(
        "Hardware-ID wird auf dieser Plattform nicht unterstützt".to_string(),
    ))
}
