import httpClient from '@/utils/http';

import {
  ControllerResponse,
  ModelAnswerSheet,
  ServiceCopyAnswerSheetRequest,
  ServiceCreateAnswerSheetRequest,
  ServiceGetAnswerSheetListResponse,
  ServiceUpdateAnswerSheetRequest
} from './data-contracts';
export default {
  /**
   * @description 创建新的答题卡
   */
  answerSheetsCreate: (answer_sheet: ServiceCreateAnswerSheetRequest) => {
    return httpClient.post<
      ControllerResponse & {
        data?: ModelAnswerSheet;
      }
    >(`/answer-sheets`, { params: answer_sheet });
  },
  /**
   * @description 分页获取答题卡列表，支持多种过滤条件
   */
  answerSheetsList: (query: {
    /**
     * 页码
     * @default 1
     */
    page?: number;
    /**
     * 每页数量
     * @default 10
     */
    page_size?: number;
    /** 答题卡名称（模糊查询） */
    name?: string;
    /** 答题卡组件ID */
    component_id?: string;
    /** 是否启用 */
    is_enable?: boolean;
  }) => {
    return httpClient.get<
      ControllerResponse & {
        data?: ServiceGetAnswerSheetListResponse;
      }
    >(`/answer-sheets`, { query: query });
  },
  /**
   * @description 获取所有启用状态的答题卡列表
   */
  enabledList: () => {
    return httpClient.get<
      ControllerResponse & {
        data?: ModelAnswerSheet[];
      }
    >(`/answer-sheets/enabled`);
  },
  /**
   * @description 根据ID获取答题卡详细信息
   */
  answerSheetsDetail: (id: number) => {
    return httpClient.get<
      ControllerResponse & {
        data?: ModelAnswerSheet;
      }
    >(`/answer-sheets/${id}`);
  },
  /**
   * @description 更新答题卡信息
   */
  answerSheetsUpdate: (id: number, answer_sheet: ServiceUpdateAnswerSheetRequest) => {
    return httpClient.put<
      ControllerResponse & {
        data?: ModelAnswerSheet;
      }
    >(`/answer-sheets/${id}`, { params: answer_sheet });
  },
  /**
   * @description 删除答题卡（软删除）
   */
  answerSheetsDelete: (id: number) => {
    return httpClient.delete<
      ControllerResponse & {
        message?: string;
      }
    >(`/answer-sheets/${id}`);
  },
  /**
   * @description 根据答题卡ID复制一条新的答题卡记录
   */
  copyCreate: (id: number, copy_request: ServiceCopyAnswerSheetRequest) => {
    return httpClient.post<
      ControllerResponse & {
        data?: ModelAnswerSheet;
      }
    >(`/answer-sheets/${id}/copy`, { params: copy_request });
  },
  /**
   * @description 根据调用者身份自动共享答题卡（学校管理员共享给所在学校，联考管理员共享给所有学校）
   */
  shareCreate: (id: number) => {
    return httpClient.post<
      ControllerResponse & {
        message?: string;
      }
    >(`/answer-sheets/${id}/share`);
  },
  /**
   * @description 取消答题卡的共享状态
   */
  unshareCreate: (id: number) => {
    return httpClient.post<
      ControllerResponse & {
        message?: string;
      }
    >(`/answer-sheets/${id}/unshare`);
  }
};
