package com.ruoyi.platform.controller.autoML;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.GenericsAjaxResult;
import com.ruoyi.platform.domain.AutoMlIns;
import com.ruoyi.platform.service.AutoMlInsService;
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;
import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("autoMLIns")
@Api("自动机器学习实验实例")
public class AutoMlInsController extends BaseController {

    @Resource
    private AutoMlInsService autoMLInsService;

    @GetMapping
    @ApiOperation("分页查询")
    public GenericsAjaxResult<Page<AutoMlIns>> queryByPage(AutoMlIns autoMlIns, int page, int size) throws IOException {
        PageRequest pageRequest = PageRequest.of(page, size);
        return genericsSuccess(this.autoMLInsService.queryByPage(autoMlIns, pageRequest));
    }

    @PostMapping
    @ApiOperation("新增实验实例")
    public GenericsAjaxResult<AutoMlIns> add(@RequestBody AutoMlIns autoMlIns) {
        return genericsSuccess(this.autoMLInsService.insert(autoMlIns));
    }

    @DeleteMapping("{id}")
    @ApiOperation("删除实验实例")
    public GenericsAjaxResult<String> deleteById(@PathVariable("id") Long id) {
        return genericsSuccess(this.autoMLInsService.removeById(id));
    }

    @DeleteMapping("batchDelete")
    @ApiOperation("批量删除实验实例")
    public GenericsAjaxResult<String> batchDelete(@RequestBody List<Long> ids) {
        return genericsSuccess(this.autoMLInsService.batchDelete(ids));
    }

    @PutMapping("{id}")
    @ApiOperation("终止实验实例")
    public GenericsAjaxResult<Boolean> terminateAutoMlIns(@PathVariable("id") Long id) throws Exception {
        return genericsSuccess(this.autoMLInsService.terminateAutoMlIns(id));
    }

    @GetMapping("{id}")
    @ApiOperation("查看实验实例详情")
    public GenericsAjaxResult<AutoMlIns> getDetailById(@PathVariable("id") Long id) {
        return genericsSuccess(this.autoMLInsService.getDetailById(id));
    }
}
