package com.education.api.controller.admin.education;

import com.education.auth.annotation.Logical;
import com.education.auth.annotation.RequiresPermissions;
import com.education.business.service.education.StepModelService;
import com.education.common.base.BaseController;
import com.education.common.model.PageInfo;
import com.education.common.utils.Result;
import com.education.model.dto.StepModelDto;
import com.education.model.entity.StepModel;
import com.education.model.request.PageParam;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Date;

/**
 * 模版管理
 */
@RequestMapping("/system/stepModel")
@RestController
public class StepModelController extends BaseController {

    @Resource
    private StepModelService stepModelService;

    /**
     * 模版分页列表
     * @param pageParam
     * @param  stepModel
     * @return
     */
    @GetMapping
    //@RequiresPermissions("system:stepModel:list")
    public Result selectPage(PageParam pageParam,  StepModel stepModel) {
        PageInfo<StepModel> list = stepModelService.selectPageList(pageParam,  stepModel);
        return Result.success( list);
    }

    /**
     * 添加或修改
     * @param  stepModelDto
     * @return
     */
    @PostMapping
    //@RequiresPermissions(value = {"system:stepModel:save","system:stepModel:update"}, logical = Logical.OR)
    public Result saveOrUpdate(@RequestBody StepModelDto stepModelDto) {
        StepModel model = new StepModel();
        model.setId(stepModelDto.getId());
        model.setCreateDate(new Date());
        model.setUpdateDate(new Date());
        model.setName(stepModelDto.getName());
        model.setPrompt(stepModelDto.getPrompt());
        model.setAgentId(stepModelDto.getAgentId());
        model.setReserve(stepModelDto.getReserve());
        stepModelService.saveOrUpdate( model);
        return Result.success();
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("{id}")
    //@RequiresPermissions("system:stepModel:deleteById")
    public Result deleteById(@PathVariable Integer id) {
         stepModelService.removeById(id);
        return Result.success();
    }

}
