//! Task dependency handlers

use crate::error::{ApiError, ApiResult};
use crate::state::AppState;
use axum::{
    extract::{Path, State},
    http::StatusCode,
    Json,
};
use serde::{Deserialize, Serialize};
use syntaxis_core::persistence::Database;

/// Add dependency request
#[derive(Debug, Deserialize)]
pub struct AddDependencyRequest {
    /// Depends on task ID
    #[allow(dead_code)]
    pub depends_on: String,
}

/// Dependency DTO
#[derive(Debug, Serialize)]
pub struct DependencyDto {
    /// Task ID
    pub task_id: String,
    /// Depends on task ID
    pub depends_on: String,
}

/// Add a task dependency
#[allow(unused_variables)]
pub async fn add_dependency(
    State(state): State<AppState>,
    Path((_project_id, _task_id)): Path<(String, String)>,
    Json(_req): Json<AddDependencyRequest>,
) -> ApiResult<(StatusCode, Json<DependencyDto>)> {
    // NOTE: TaskDependencyEntity not yet migrated to Database trait
    Err(ApiError::Internal(
        "Task dependencies not yet implemented with new Database trait".to_string(),
    ))
}

/// Get dependencies for a task
pub async fn get_dependencies(
    State(state): State<AppState>,
    Path((project_id, _task_id)): Path<(String, String)>,
) -> ApiResult<Json<Vec<DependencyDto>>> {
    // Verify project exists
    let _ = state
        .db
        .get_project(&project_id)
        .await?
        .ok_or_else(|| ApiError::NotFound(format!("Project {} not found", project_id)))?;

    // NOTE: TaskDependencyEntity not yet migrated
    Ok(Json(Vec::new()))
}

/// Remove a task dependency
pub async fn remove_dependency(
    State(_state): State<AppState>,
    Path((_project_id, _task_id, _depends_on)): Path<(String, String, String)>,
) -> ApiResult<StatusCode> {
    // NOTE: TaskDependencyEntity not yet migrated
    Err(ApiError::Internal(
        "Task dependencies not yet implemented with new Database trait".to_string(),
    ))
}

/// Delete a task dependency (alias for remove_dependency)
pub async fn delete_dependency(
    state: State<AppState>,
    path: Path<(String, String, String)>,
) -> ApiResult<StatusCode> {
    remove_dependency(state, path).await
}
