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.MachineLearnIns;
import com.ruoyi.platform.service.MachineLearnInsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;

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

    @Resource
    private MachineLearnInsService machineLearnInsService;

    @GetMapping
    @ApiOperation("分页查询")
    public GenericsAjaxResult<Page<MachineLearnIns>> queryByPage(Long machineLearnId, int page, int size) {
        PageRequest pageRequest = PageRequest.of(page, size);
        return genericsSuccess(this.machineLearnInsService.queryByPage(machineLearnId, pageRequest));
    }

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

    @PutMapping
    @ApiOperation("编辑实验实例")
    public GenericsAjaxResult<MachineLearnIns> edit(@RequestBody MachineLearnIns machineLearnIns){
        return genericsSuccess(this.machineLearnInsService.update(machineLearnIns));
    }

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

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

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

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