import { request } from '@/api/request'

export interface DetectionPoint {
  id: number
  resource_category: string
  metric_code: string
  alert_rule_id: number
  fault_type: string
  knowledge_type: 'document' | 'faq'
  knowledge_id: number
  knowledge_title: string
  enabled: boolean
  remarks: string
}

export interface KnowledgeRecommendation {
  knowledge_type: 'document' | 'faq'
  knowledge_id: number
  title: string
  status: string
  resource_category: string
  metric_code: string
  alert_rule_id: number
  fault_type: string
  detection_point_id: number
  score: number
  reason: string
}

export interface IncidentKnowledgeRelation {
  id: number
  incident_id: number
  ticket_id: number
  knowledge_type: 'document' | 'faq'
  knowledge_id: number
  knowledge_title: string
  relation_type: string
  source: string
  score: number
  reason: string
  created_at: string
}

export const fetchKnowledgeRecommendations = (params: {
  resource_category?: string
  metric_code?: string
  alert_rule_id?: number
  fault_type?: string
  limit?: number
}) => request.get('/Kb/v1/knowledge/recommend', { params })

export const fetchIncidentKnowledge = (incidentId: number) => request.get(`/Kb/v1/knowledge/incidents/${incidentId}/relations`)

export const fetchTicketKnowledge = (ticketId: number) => request.get('/Kb/v1/knowledge/relations', { params: { ticket_id: ticketId } })

export const relateIncidentKnowledge = (data: {
  incident_id?: number
  ticket_id?: number
  knowledge_type: 'document' | 'faq'
  knowledge_id: number
  knowledge_title?: string
  relation_type?: string
  source?: string
  score?: number
  reason?: string
}) => request.post('/Kb/v1/knowledge/relations', data)

export const createPostmortemDraft = (data: Record<string, any>) => request.post('/Kb/v1/knowledge/postmortem/draft', data)
