//! Task assignment 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;

/// Assign task request
#[derive(Debug, Deserialize)]
pub struct AssignTaskRequest {
    /// User ID to assign task to
    #[allow(dead_code)]
    pub user_id: String,
}

/// Assignment DTO
#[derive(Debug, Serialize)]
pub struct AssignmentDto {
    /// Task ID
    pub task_id: String,
    /// User ID
    pub user_id: String,
    /// Assigned at timestamp
    pub assigned_at: String,
}

/// Assign a task to a user
#[allow(unused_variables)]
pub async fn assign_task(
    State(state): State<AppState>,
    Path((_project_id, _task_id)): Path<(String, String)>,
    Json(_req): Json<AssignTaskRequest>,
) -> ApiResult<(StatusCode, Json<AssignmentDto>)> {
    // NOTE: UserEntity not yet migrated to Database trait
    // This is a stub implementation
    Err(ApiError::Internal(
        "Task assignments not yet implemented with new Database trait".to_string(),
    ))
}

/// Get assignments for a project
#[allow(dead_code)]
pub async fn get_assignments(
    State(state): State<AppState>,
    Path(project_id): Path<String>,
) -> ApiResult<Json<Vec<AssignmentDto>>> {
    // Verify project exists
    let _ = state
        .db
        .get_project(&project_id)
        .await?
        .ok_or_else(|| ApiError::NotFound(format!("Project {} not found", project_id)))?;

    // NOTE: UserEntity and assignments not yet migrated
    Ok(Json(Vec::new()))
}

/// Unassign a task from a user
pub async fn unassign_task(
    State(_state): State<AppState>,
    Path((_project_id, _task_id)): Path<(String, String)>,
) -> ApiResult<StatusCode> {
    // NOTE: UserEntity not yet migrated
    Err(ApiError::Internal(
        "Task assignments not yet implemented with new Database trait".to_string(),
    ))
}

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

    // NOTE: UserEntity and assignments not yet migrated
    Ok(Json(Vec::new()))
}

/// User DTO
#[derive(Debug, Serialize)]
pub struct UserDto {
    /// User ID
    pub id: String,
    /// User name
    pub name: String,
    /// User email
    pub email: String,
}

/// Create user request
#[derive(Debug, Deserialize)]
pub struct CreateUserRequest {
    /// User name
    #[allow(dead_code)]
    pub name: String,
    /// User email
    #[allow(dead_code)]
    pub email: String,
}

/// Create a new user
pub async fn create_user(
    State(_state): State<AppState>,
    Json(_req): Json<CreateUserRequest>,
) -> ApiResult<(StatusCode, Json<UserDto>)> {
    // NOTE: UserEntity not yet migrated to Database trait
    Err(ApiError::Internal(
        "User management not yet implemented with new Database trait".to_string(),
    ))
}

/// List all users
pub async fn list_users(State(_state): State<AppState>) -> ApiResult<Json<Vec<UserDto>>> {
    // NOTE: UserEntity not yet migrated
    Ok(Json(Vec::new()))
}
