import request from '@/utils/request';

// 获取问题列表
export async function getQuestionList(params: API.QuestionListRequest): Promise<API.Response<API.QuestionRecord[]>> {
  return request('/portals/qanda', {
    method: 'GET',
    params,
  });
}

// 获取问题分页列表
export async function getQuestionPage(params: API.PageRequest): Promise<API.Response<API.PageResponse<API.QuestionRecord>>> {
  return request('/portals/qanda/getPage', {
    method: 'POST',
    data: params,
  });
}

// 获取问题详情
export async function getQuestionDetail(id: string): Promise<API.Response<API.QuestionRecord>> {
  return request(`/portals/qanda/${id}`, {
    method: 'GET',
  });
}

// 回答问题
export async function answerQuestion(params: API.QuestionAnswerRequest): Promise<API.Response<string>> {
  return request('/portals/qanda', {
    method: 'PUT',
    data: params,
  });
}

// 标记问题为已阅
export async function markQuestionSeen(id: string): Promise<API.Response<string>> {
  return request('/portals/qanda/seeEdit', {
    method: 'POST',
    data: {
      id: id
    },
  });
}

// 标记问题为已阅（新增接口）
export async function markQuestionSeeEdit(id: string): Promise<API.Response<string>> {
  return request(`/portals/qanda/seeEdit`, {
    method: 'POST',
    data: { id },
  });
}

// 更新问题状态（发布/置顶）
export async function updateQuestionStatus(params: API.QuestionStatusRequest): Promise<API.Response<string>> {
  return request('/portals/qanda/status', {
    method: 'PUT',
    data: params,
  });
}

// 删除单个问题
export async function deleteQuestion(id: string): Promise<API.Response<string>> {
  return request(`/portals/qanda/${id}`, {
    method: 'DELETE',
  });
}

// 批量删除问题
export async function batchDeleteQuestion(ids: string[]): Promise<API.Response<string>> {
  return request('/portals/qanda/batch', {
    method: 'DELETE',
    data: { ids },
  });
}

// 添加问题
export async function addQuestion(params: API.QuestionAddRequest): Promise<API.Response<string>> {
  return request('/portals/qanda', {
    method: 'POST',
    data: params,
  });
}
