use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use uuid::Uuid;

/// Wipe profile with pre/post configuration
#[derive(Debug, Clone, sqlx::FromRow, Serialize)]
pub struct WipeProfile {
    pub id: Uuid,
    pub license_id: Uuid,
    pub profile_name: String,
    pub description: Option<String>,
    pub pre_wipe_config: serde_json::Value,
    pub post_wipe_config: serde_json::Value,
    pub created_at: DateTime<Utc>,
    pub updated_at: DateTime<Utc>,
}

/// Wipe schedule
#[derive(Debug, Clone, sqlx::FromRow, Serialize)]
pub struct WipeSchedule {
    pub id: Uuid,
    pub license_id: Uuid,
    pub wipe_profile_id: Uuid,
    pub schedule_name: String,
    pub wipe_type: String,
    pub cron_expression: String,
    pub timezone: String,
    pub wipe_blueprints: bool,
    pub is_active: bool,
    pub next_scheduled_run: Option<DateTime<Utc>>,
    pub created_at: DateTime<Utc>,
}

/// Wipe execution history
#[derive(Debug, Clone, sqlx::FromRow, Serialize)]
pub struct WipeHistory {
    pub id: Uuid,
    pub license_id: Uuid,
    pub wipe_schedule_id: Option<Uuid>,
    pub wipe_profile_id: Uuid,
    pub wipe_type: String,
    pub trigger_type: String,
    pub status: String,
    pub started_at: Option<DateTime<Utc>>,
    pub completed_at: Option<DateTime<Utc>>,
    pub map_used: Option<String>,
    pub plugins_wiped: Option<Vec<String>>,
    pub plugins_preserved: Option<Vec<String>>,
    pub backup_reference: Option<String>,
    pub error_message: Option<String>,
    pub execution_log: Option<serde_json::Value>,
    pub created_at: DateTime<Utc>,
}

/// Map in the library
#[derive(Debug, Clone, sqlx::FromRow, Serialize)]
pub struct MapEntry {
    pub id: Uuid,
    pub license_id: Uuid,
    pub filename: String,
    pub display_name: String,
    pub storage_path: String,
    pub file_size_bytes: i64,
    pub map_type: String,
    pub seed: Option<i32>,
    pub world_size: Option<i32>,
    pub thumbnail_path: Option<String>,
    pub checksum: String,
    pub uploaded_at: DateTime<Utc>,
}

/// Pre-wipe config structure (typed version of JSONB)
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PreWipeConfig {
    pub enabled: bool,
    pub backup_before_wipe: bool,
    pub countdown_warnings: Vec<i32>,
    pub countdown_unit: String,
    pub countdown_messages: Option<std::collections::HashMap<String, String>>,
    pub kick_players_before_wipe: bool,
    pub kick_message: String,
    pub run_final_save: bool,
    pub discord_pre_announce: bool,
    pub pushbullet_notify: bool,
    pub custom_commands_before: Vec<String>,
}

/// Post-wipe config structure (typed version of JSONB)
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PostWipeConfig {
    pub enabled: bool,
    pub verify_server_started: bool,
    pub verify_correct_map: bool,
    pub verify_plugins_loaded: bool,
    pub verify_player_slots_open: bool,
    pub max_restart_attempts: i32,
    pub health_check_timeout_seconds: i32,
    pub discord_post_announce: bool,
    pub pushbullet_notify: bool,
    pub rollback_on_failure: bool,
    pub post_wipe_commands: Vec<String>,
}
