use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PleskServer {
    pub id: i32,
    pub name: String,
    pub host: String,
    pub port: i32,
    pub use_https: bool,
    pub connection_status: String,
    pub last_connected: Option<String>,
    pub is_active: bool,
}

#[derive(Debug, Deserialize)]
pub struct PleskServerConfig {
    pub name: String,
    pub host: String,
    #[serde(default = "default_port")]
    pub port: i32,
    pub api_key: String,
    pub username: String,
    pub password: String,
    #[serde(default = "default_true")]
    pub use_https: bool,
    #[serde(default = "default_verify_ssl")]
    pub verify_ssl: bool,
}

fn default_port() -> i32 {
    8443
}
fn default_true() -> bool {
    true
}
fn default_verify_ssl() -> bool {
    true
}

#[derive(Debug, Deserialize)]
pub struct PleskServerTest {
    pub id: Option<i32>,
    pub host: String,
    pub port: i32,
    pub api_key: String,
    pub username: String,
    pub password: String,
    pub code: Option<String>,
}

#[derive(Debug, Serialize)]
pub struct PleskServerTestResult {
    pub success: bool,
    pub message: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub requires_2fa: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub version: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SapServer {
    pub id: i32,
    pub name: String,
    pub host: String,
    pub port: i32,
    pub company_db: String,
    pub connection_status: String,
    pub last_connected: Option<String>,
    pub is_active: bool,
}

#[derive(Debug, Deserialize)]
pub struct SapServerConfig {
    pub name: String,
    pub host: String,
    #[serde(default = "default_sap_port")]
    pub port: i32,
    pub company_db: String,
    pub username: String,
    pub password: String,
    #[serde(default = "default_true")]
    pub use_ssl: bool,
    #[serde(default = "default_timeout")]
    pub timeout_seconds: i32,
}

fn default_sap_port() -> i32 {
    50000
}
fn default_timeout() -> i32 {
    30
}

#[derive(Debug, Deserialize)]
pub struct SapServerTest {
    pub id: Option<i32>,
    pub host: String,
    pub port: i32,
    pub company_db: String,
    pub username: String,
    pub password: String,
}

#[derive(Debug, Serialize)]
pub struct SapServerTestResult {
    pub success: bool,
    pub message: String,
}
