package com.lanyuanxiaoyao.service.ai.knowledge.controller;

import com.lanyuanxiaoyao.service.ai.core.entity.amis.AmisResponse;
import com.lanyuanxiaoyao.service.ai.knowledge.service.SegmentService;
import java.util.concurrent.ExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lanyuanxiaoyao
 * @version 20250528
 */
@RestController
@RequestMapping("segment")
public class SegmentController {
  private static final Logger logger = LoggerFactory.getLogger(SegmentController.class);

  private final SegmentService segmentService;

  public SegmentController(SegmentService segmentService) {
    this.segmentService = segmentService;
  }

  @GetMapping("list")
  public AmisResponse<?> list(@RequestParam("knowledge_id") Long knowledgeId, @RequestParam("group_id") Long groupId) throws ExecutionException, InterruptedException {
    return AmisResponse.responseCrudData(segmentService.list(knowledgeId, groupId));
  }

  @GetMapping("delete")
  public AmisResponse<?> delete(@RequestParam("knowledge_id") Long knowledgeId, @RequestParam("segment_id") Long segmentId) throws ExecutionException, InterruptedException {
    segmentService.remove(knowledgeId, segmentId);
    return AmisResponse.responseSuccess();
  }
}
