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

import com.education.business.service.education.HomeworkGoalInfoService;
import com.education.business.service.education.HomeworkInfoService;
import com.education.common.base.BaseController;
import com.education.common.utils.Result;
import com.education.common.utils.ResultCode;
import com.education.model.dto.HomeworkGoalInfoDto;
import com.education.model.entity.HomeworkGoalInfo;
import com.education.model.entity.HomeworkInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 作业与目标导向配置管理
 */
@RequestMapping("/system/homeworkGoalInfo")
@RestController
public class HomeworkGoalInfoController extends BaseController {

    @Autowired
    private HomeworkInfoService homeworkInfoService;

    @Autowired
    private HomeworkGoalInfoService homeworkGoalInfoService;

    /**
     * 添加作业与导向目标布置
     * @param homeworkGoalInfo
     * @return
     */
    @PostMapping
    //@RequiresPermissions("system:homeworkGoalInfo:save")
    public Result add(@RequestBody HomeworkGoalInfo homeworkGoalInfo) {
        homeworkGoalInfoService.saveOrUpdate(homeworkGoalInfo);
        //todo homeworkInfoService update question number
        return Result.success();
    }

    /**
     * 删除作业与导向目标布置
     * @param homeworkInfoId 作业布置id
     * @param goalInfoId 导向目标id
     * @return
     */
    @DeleteMapping("/{homeworkInfoId}/{goalInfoId}")
    //@RequiresPermissions("system:homeworkGoalInfo:delete")
    public Result delete(@PathVariable Integer homeworkInfoId, @PathVariable Integer goalInfoId) {
        //todo check homework info's relation and status,delete relative goal infos,update homework info's question number
        homeworkGoalInfoService.removeHomeworkGoalInfo(homeworkInfoId, goalInfoId);
        return Result.success(ResultCode.SUCCESS, "删除成功");
    }

//    /**
//     * 添加或修改
//     * @param homeworkGoalInfoDto
//     * @return
//     */
//    @PostMapping
//    //@RequiresPermissions(value = {"system:homeworkGoalInfo:save","system:homeworkGoalInfo:update"}, logical = Logical.OR)
//    public Result saveOrUpdate(@RequestBody HomeworkGoalInfoDto homeworkGoalInfoDto) {
//        homeworkGoalInfoService.saveOrUpdate(homeworkGoalInfoDto);
//        return Result.success();
//    }

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

}