//! Data types and DTOs for the dashboard

use serde::{Deserialize, Serialize};

/// Project data transfer object
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProjectDto {
    /// Project ID
    pub id: String,
    /// Project name
    pub name: String,
    /// Project version
    pub version: String,
    /// Project description
    pub description: String,
    /// Project type
    pub project_type: String,
    /// Current phase
    pub current_phase: String,
    /// Creation timestamp
    pub created_at: String,
    /// Last update timestamp
    pub updated_at: String,
}

/// Create project request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateProjectRequest {
    /// Project name
    pub name: String,
    /// Project description
    pub description: Option<String>,
    /// Project type
    pub project_type: Option<String>,
}

/// Update project request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UpdateProjectRequest {
    /// Project description
    pub description: Option<String>,
    /// Project version
    pub version: Option<String>,
}

/// Task priority level
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
#[derive(Default)]
pub enum TaskPriority {
    /// Low priority task
    Low,
    /// Medium priority task
    #[default]
    Medium,
    /// High priority task
    High,
    /// Critical priority task
    Critical,
}

impl TaskPriority {
    /// Get the display label for this priority
    pub fn label(&self) -> &'static str {
        match self {
            Self::Low => "Low",
            Self::Medium => "Medium",
            Self::High => "High",
            Self::Critical => "Critical",
        }
    }
}

/// Task type
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
#[derive(Default)]
pub enum TaskType {
    /// Feature implementation task
    #[default]
    Feature,
    /// Bug fix task
    BugFix,
    /// Documentation task
    Documentation,
    /// Testing task
    Testing,
    /// Deployment task
    Deployment,
    /// Maintenance task
    Maintenance,
}

impl TaskType {
    /// Get the display label for this task type
    pub fn label(&self) -> &'static str {
        match self {
            Self::Feature => "Feature",
            Self::BugFix => "Bug Fix",
            Self::Documentation => "Documentation",
            Self::Testing => "Testing",
            Self::Deployment => "Deployment",
            Self::Maintenance => "Maintenance",
        }
    }
}

/// Checklist item DTO
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ChecklistItemDto {
    /// Item ID
    pub id: String,
    /// Task ID
    pub task_id: String,
    /// Description
    pub description: String,
    /// Completion status
    pub completed: bool,
    /// Completion timestamp
    pub completed_at: Option<String>,
    /// Creation timestamp
    pub created_at: String,
    /// Task priority (default: Medium)
    #[serde(default)]
    pub priority: TaskPriority,
    /// Task type (default: Feature)
    #[serde(default, rename = "type")]
    pub task_type: TaskType,
}

/// Add checklist item request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AddChecklistItemRequest {
    /// Task ID
    pub task_id: String,
    /// Description
    pub description: String,
}

/// Update checklist item request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UpdateChecklistItemRequest {
    /// Completion status
    pub completed: Option<bool>,
}

/// Security assessment DTO
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SecurityAssessmentDto {
    /// Assessment ID
    pub id: String,
    /// Security profile
    pub profile: String,
    /// Risk level
    pub risk_level: String,
    /// Passed rules count
    pub passed_rules: i32,
    /// Failed rules count
    pub failed_rules: i32,
    /// Critical issues count
    pub critical_issues: i32,
    /// Assessment timestamp
    pub assessment_date: String,
}

/// Project status DTO
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProjectStatusDto {
    /// Project ID
    pub id: String,
    /// Current phase
    pub current_phase: String,
    /// Checklist completion percentage
    pub checklist_completion: f64,
    /// Active tools count
    pub active_tools: usize,
    /// Latest security assessment
    pub latest_assessment: Option<SecurityAssessmentDto>,
}

/// Tool configuration DTO
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ToolDto {
    /// Tool name
    pub name: String,
    /// Tool enabled status
    pub enabled: bool,
    /// Tool description
    pub description: String,
}

/// API error response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ApiErrorResponse {
    /// Error message
    pub error: String,
    /// HTTP status code
    pub status: u16,
}

/// syntaxis event (WebSocket)
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "PascalCase")]
pub enum ProjectEvent {
    /// Project was created
    ProjectCreated {
        /// Project ID
        project_id: String,
        /// Project name
        project_name: String,
    },
    /// Project was updated
    ProjectUpdated {
        /// Project ID
        project_id: String,
    },
    /// Task was completed
    TaskCompleted {
        /// Project ID
        project_id: String,
        /// Task ID
        task_id: String,
    },
    /// Task was added
    TaskAdded {
        /// Project ID
        project_id: String,
        /// Task ID
        task_id: String,
    },
    /// Phase transition occurred
    PhaseTransition {
        /// Project ID
        project_id: String,
        /// Previous phase
        from_phase: String,
        /// New phase
        to_phase: String,
    },
}

/// User authentication token response
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AuthTokenResponse {
    /// JWT token
    pub token: String,
    /// Token expiration time (seconds from now)
    pub expires_in: i64,
    /// User ID
    pub user_id: String,
}

/// Login request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LoginRequest {
    /// User email
    pub email: String,
    /// User password
    pub password: String,
}

/// Task comment DTO
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TaskCommentDto {
    /// Comment ID
    pub id: String,
    /// Task ID
    pub task_id: String,
    /// User ID who created the comment
    pub user_id: String,
    /// User name who created the comment
    pub user_name: String,
    /// Comment content
    pub content: String,
    /// Creation timestamp
    pub created_at: String,
    /// Update timestamp
    pub updated_at: String,
}

/// Add comment request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AddCommentRequest {
    /// Comment content
    pub content: String,
}

/// Task attachment DTO
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TaskAttachmentDto {
    /// Attachment ID
    pub id: String,
    /// Task ID
    pub task_id: String,
    /// Original filename
    pub filename: String,
    /// File size in bytes
    pub size: u64,
    /// MIME type
    pub mime_type: String,
    /// Upload timestamp
    pub uploaded_at: String,
    /// Uploader user ID
    pub uploaded_by: String,
}

/// Filter preset DTO
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FilterPresetDto {
    /// Preset ID
    pub id: String,
    /// User ID who owns this preset
    pub user_id: String,
    /// Preset name
    pub name: String,
    /// Filter configuration as JSON
    pub filters_json: String,
    /// Creation timestamp
    pub created_at: String,
}

/// Create filter preset request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateFilterPresetRequest {
    /// Preset name
    pub name: String,
    /// Filter configuration as JSON
    pub filters_json: String,
}

/// Update deadline request
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UpdateDeadlineRequest {
    /// New deadline (ISO 8601 format)
    pub deadline: String,
}
