import { Injectable } from '@angular/core';
import { Get, Post, requestDone } from '../http.decorators';
import { _BaseApi } from './_base';

@Injectable({ providedIn: 'root' })
export class KnowledgeApi extends _BaseApi {
  async getDocList(data: Knowledge.GetDocListParams) {
    return this.http.get<Promise<Knowledge.GetDocListResponse>>('/knowledge/doc/list', data);
  }
  async getAllDoc(company: string) {
    return this.http.get<Promise<Knowledge.Doc[]>>('/knowledge/doc/listAll', { company });
  }
  async removeDoc(id: number) {
    return this.http.get<ResWrapper<void>>('/knowledge/doc/remove', { id });
  }

  async getRiskItems(data: Knowledge.GetRiskItemListParams): Promise<Knowledge.GetRiskItemListResponse> {
    return this.http.get('/risk/point/list', data);
  }

  async getMyRiskItems(showType: number): Promise<Knowledge.RiskItem[]> {
    return this.http.get('/risk/point/myList', { showType });
  }

  async getAllItems(): Promise<Knowledge.RiskItem[]> {
    return this.http.get('/risk/point/myList', { showType: 0 });
  }

  @Post('/risk/point/create')
  async createRiskItem(data: Partial<Knowledge.RiskItem>): Promise<ResWrapper<void>> {
    requestDone(data);
  }

  @Post('/risk/point/update')
  async updateRiskItem(data: Partial<Knowledge.RiskItem>): Promise<ResWrapper<void>> {
    requestDone(data);
  }

  @Get('/risk/point/remove', false, ['id'])
  async deleteRiskItem(id: number): Promise<ResWrapper<void>> {
    requestDone({ id });
  }

  async getRiskItemHistory(data: Knowledge.GetRiskItemHistoryParams): Promise<Knowledge.GetRiskItemListResponse> {
    return this.http.get('/risk/point/history/list', data);
  }

  async getRiskItemHistoryDetail(riskPointId: number, id: number): Promise<Knowledge.GetRiskItemListResponse> {
    return this.http.get('/risk/point/history/list/latestTwo', { riskPointId, id });
  }

  @Get('/knowledge/risk-levels')
  async getRiskLevels(): Promise<Knowledge.RiskLevelResponse> {
    requestDone();
  }

  @Get('/risk/type/listAll')
  async getRiskTypes(): Promise<Knowledge.RiskCategoryResponse> {
    requestDone();
  }

  @Post('/risk/type/create')
  async createRiskType(data: Partial<Knowledge.RiskTypeDto>): Promise<Knowledge.RiskTypeDto> {
    requestDone(data);
  }

  @Post('/risk/type/update')
  async updateRiskType(data: Partial<Knowledge.RiskTypeDto>): Promise<ResWrapper<void>> {
    requestDone(data);
  }

  @Get('/risk/type/remove', false, ['id'])
  async deleteRiskType(id: number): Promise<ResWrapper<void>> {
    requestDone({ id });
  }

  @Post('/risk/category/create')
  async createRiskCategory(
    data: Partial<Knowledge.RiskCategoryDto & { type: number }>
  ): Promise<Knowledge.RiskCategoryDto> {
    requestDone(data);
  }

  @Post('/risk/category/update')
  async updateRiskCategory(data: Partial<Knowledge.RiskCategoryDto & { type: number }>): Promise<ResWrapper<void>> {
    requestDone(data);
  }

  @Get('/risk/category/remove', false, ['id'])
  async deleteRiskCategory(id: number): Promise<ResWrapper<void>> {
    requestDone({ id });
  }
}
