import { Injectable } from '@angular/core';
import { _BaseApi } from './_base';

@Injectable({ providedIn: 'root' })
export class HazardApi extends _BaseApi {
  async createHazard(data: Partial<Hazard.HazardDto>) {
    return this.http.post<Promise<ResWrapper<void>>>('/trouble/create', data);
  }
  async updateHazard(data: Partial<Hazard.HazardDto>) {
    return this.http.post<Promise<ResWrapper<void>>>('/trouble/update', data);
  }

  async getHazards(params: Hazard.GetHazardsParams) {
    return this.http.get<Promise<{ items: Hazard.HazardDto[]; total: number }>>('/trouble/list', params);
  }

  async passHazard(id: number, comment: string) {
    return this.http.get<Promise<ResWrapper<void>>>('/trouble/pass', { id, toUserRemark: comment });
  }

  async refuseHazard(id: number, comment: string) {
    return this.http.get<Promise<ResWrapper<void>>>('/trouble/refuse', { id, toUserRemark: comment });
  }

  async updateHazardPlan(id: number, data: Partial<Hazard.HazardPlan>) {
    return this.http.post<Promise<ResWrapper<void>>>('/trouble/planUpdate', { ...data, id });
  }
  async passHazardPlan(id: number, comment: string) {
    return this.http.get<Promise<ResWrapper<void>>>('/trouble/planPass', { id, toUserRemark: comment });
  }

  async refuseHazardPlan(id: number, comment: string) {
    return this.http.get<Promise<ResWrapper<void>>>('/trouble/planRefuse', { id, toUserRemark: comment });
  }

  async createHazardProgress(data: Partial<Hazard.Handle>) {
    return this.http.post<Promise<ResWrapper<void>>>('/trouble/resolveHandleCreate', data);
  }

  async checkHazard(data: Hazard.ResolveParams) {
    return this.http.post<Promise<ResWrapper<void>>>('/trouble/resolveCheck', data);
  }

  async createPlan(data: Partial<Hazard.InspectionPlan>) {
    return this.http.post<Promise<ResWrapper<void>>>('/troubleshoot/create', data);
  }
  async updatePlan(data: Partial<Hazard.InspectionPlan>) {
    return this.http.post<Promise<ResWrapper<void>>>('/troubleshoot/update', data);
  }
  async withdrawPlan(id: number) {
    return this.http.get<Promise<ResWrapper<void>>>('/troubleshoot/remove', { id });
  }
  async publishPlan(id: number) {
    return this.http.get<Promise<ResWrapper<void>>>('/troubleshoot/publish', { id });
  }
  async getPlanDetail(id: number) {
    return this.http.get<Promise<Hazard.InspectionPlanDetail>>('/troubleshoot/detail', { id });
  }
  async getPlans(params: Hazard.GetPlansParams) {
    return this.http.get<Promise<Hazard.PlanListResponse>>('/troubleshoot/list', params);
  }

  async createPlanHandle(data: Partial<Hazard.InspectionPlanHandleDto>) {
    return this.http.post<Promise<Hazard.InspectionPlanHandleDto>>('/troubleshoot/plan/handle/create', data);
  }

  async updatePlanHandle(data: Partial<Hazard.InspectionPlanHandleDto>) {
    return this.http.post<Promise<Hazard.InspectionPlanHandleDto>>('/troubleshoot/plan/handle/update', data);
  }

  async removePlanHandle(id: number) {
    return this.http.get<Promise<ResWrapper<void>>>('/troubleshoot/plan/handle/remove', { id });
  }

  async reportTask(data: Hazard.ReportTaskParams) {
    return this.http.post<Promise<ResWrapper<void>>>('/troubleshoot/plan/handle/opinionUpdate', data);
  }
  async copyTasksToTurn(data: Hazard.CopyTasksToTurnParams) {
    return this.http.post<Promise<ResWrapper<void>>>('/troubleshoot/plan/handle/copyTasksToTurn', data);
  }
  async copyTasksToRound(data: Hazard.CopyTasksToRoundParams) {
    return this.http.post<Promise<ResWrapper<void>>>('/troubleshoot/plan/handle/copyTasksToRound', data);
  }
}
