package com.sckw.path.controller;

import com.sckw.path.entity.req.AddPathParam;
import com.sckw.path.entity.req.LinePathFindListParam;
import com.sckw.path.entity.req.SelectPathParam;
import com.sckw.path.entity.req.UpdatePathParam;
import com.sckw.path.entity.res.PathFindListRes;
import com.sckw.path.service.KwPathService;
import com.sckw.core.model.page.PageRes;
import com.sckw.core.web.response.HttpResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * @desc: 路径服务
 * @author: Lt
 * @date: 2024-04-16
 */
@Validated
@RestController
@RequestMapping("/path")
public class KwPathController {
    @Autowired
    KwPathService kwPathService;

    @PostMapping(value = "/add", produces = MediaType.APPLICATION_JSON_VALUE)
    public HttpResult add(@RequestBody @Validated AddPathParam addPathParam) {
        kwPathService.add(addPathParam);
        return HttpResult.ok("新增路径成功");
    }

    @GetMapping("/detail")
    public HttpResult detail(@RequestParam("id") Long id) {
        return HttpResult.ok(kwPathService.detail(id));
    }

    @PostMapping(value = "/update", produces = MediaType.APPLICATION_JSON_VALUE)
    public HttpResult update(@RequestBody @Validated UpdatePathParam updatePathParam) {
        kwPathService.update(updatePathParam);
        return HttpResult.ok("编辑路径成功");
    }

    @PostMapping(value = "/select", produces = MediaType.APPLICATION_JSON_VALUE)
    public HttpResult select(@RequestBody SelectPathParam params) {
        return HttpResult.ok(kwPathService.select(params));
    }

    //@PostMapping(value = "/choose", produces = MediaType.APPLICATION_JSON_VALUE)
    //public HttpResult choose(@RequestBody ChoosePathParam params) {
    //    return HttpResult.ok(kwPathService.choose(params));
    //}

    /**
    * @Description: 路径批量删除
    * @Author: Lt
    * @Date: 2024/4/17 0017 10:00
    */
    @GetMapping("/batchDelete")
    public HttpResult batchDelete(@RequestParam(value = "ids") List<Long> ids) {
        kwPathService.batchDelete(ids);
        return HttpResult.ok("批量删除成功");
    }

    /**
    * @Description: 路径列表
    * @Author: Lt
    * @Date: 2024/5/6 0006 10:12
    */
    @PostMapping("/findList")
    public HttpResult findList(@RequestBody LinePathFindListParam params) {
        PageRes<PathFindListRes> list = kwPathService.findList(params);
        return HttpResult.ok(list);
    }
}
