use crate::{ApiResponse, error::ApiError};
use actix_web::{HttpResponse, Result, web};
use service::AppService;
use session::Session;

#[utoipa::path(
    post,
    path = "/api/projects",
    request_body = service::project::init::ProjectInitParams,
    responses(
        (status = 200, description = "Create project", body = ApiResponse<service::project::init::ProjectInitResponse>),
        (status = 401, description = "Unauthorized"),
        (status = 404, description = "Not found"),
),
    tag = "Project"
)]
pub async fn project_create(
    service: web::Data<AppService>,
    session: Session,
    body: web::Json<service::project::init::ProjectInitParams>,
) -> Result<HttpResponse, ApiError> {
    let resp = service.project_init(&session, body.into_inner()).await?;
    Ok(ApiResponse::ok(resp).to_response())
}
