package com.ruoyi.platform.controller.machineLearn;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.GenericsAjaxResult;
import com.ruoyi.platform.domain.MachineLearn;
import com.ruoyi.platform.service.MachineLearnService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("machineLearn")
@Api("自动机器学习")
public class MachineLearnController extends BaseController {
    @Resource
    private MachineLearnService machineLearnService;

    @GetMapping
    @ApiOperation("分页查询")
    public GenericsAjaxResult<Page<MachineLearn>> queryByPage(@RequestParam("page") int page,
                                                              @RequestParam("size") int size,
                                                              @RequestParam(value = "name", required = false) String name,
                                                              @RequestParam(value = "type", required = false) String type) {
        PageRequest pageRequest = PageRequest.of(page, size);
        return genericsSuccess(this.machineLearnService.queryByPage(name, type, pageRequest));
    }

    @PostMapping
    @ApiOperation("新增自动机器学习")
    public GenericsAjaxResult<MachineLearn> add(@RequestBody MachineLearn machineLearn) {
        return genericsSuccess(this.machineLearnService.add(machineLearn));
    }

    @PutMapping
    @ApiOperation("编辑自动机器学习")
    public GenericsAjaxResult<String> edit(@RequestBody MachineLearn machineLearn) throws Exception {
        return genericsSuccess(this.machineLearnService.edit(machineLearn));
    }

    @GetMapping("/getMLDetail")
    @ApiOperation("获取自动机器学习详细信息")
    public GenericsAjaxResult<MachineLearn> getMLDetail(@RequestParam("id") Long id) {
        return genericsSuccess(this.machineLearnService.getMLDetail(id));
    }

    @DeleteMapping("{id}")
    @ApiOperation("删除自动机器学习")
    public GenericsAjaxResult<String> delete(@PathVariable("id") Long id) {
        return genericsSuccess(this.machineLearnService.delete(id));
    }

    @PostMapping("/run/{id}")
    @ApiOperation("运行自动机器学习")
    public GenericsAjaxResult<String> runMachineLearn(@PathVariable("id") Long id) throws Exception {
        return genericsSuccess(this.machineLearnService.runMachineLearn(id));
    }
}
