import request from './request';
import type { Project } from '../stores/useProjectStore';

export interface ApiResponse<T = any> {
  success: boolean;
  data?: T;
  message?: string;
  error?: string;
}

export interface CreateProjectRequest {
  name: string;
  background: string;
  researchType: 'observational' | 'interventional';
}

export interface UpdateProjectRequest {
  name?: string;
  background?: string;
  researchType?: 'observational' | 'interventional';
}

export const projectApi = {
  // 获取项目列表
  getProjects: async (): Promise<ApiResponse<Project[]>> => {
    return await request.get('/projects');
  },

  // 获取单个项目详情
  getProjectById: async (id: string): Promise<ApiResponse<Project>> => {
    return await request.get(`/projects/${id}`);
  },

  // 创建项目
  createProject: async (data: CreateProjectRequest): Promise<ApiResponse<Project>> => {
    return await request.post('/projects', data);
  },

  // 更新项目
  updateProject: async (
    id: string,
    data: UpdateProjectRequest
  ): Promise<ApiResponse<Project>> => {
    return await request.put(`/projects/${id}`, data);
  },

  // 删除项目
  deleteProject: async (id: string): Promise<ApiResponse> => {
    return await request.delete(`/projects/${id}`);
  },
};

