package com.koobietech.eas.controller;


import com.github.pagehelper.PageHelper;
import com.koobietech.eas.common.constant.Disabled;
import com.koobietech.eas.common.result.JsonPageResult;
import com.koobietech.eas.common.result.JsonResult;
import com.koobietech.eas.common.result.PageData;
import com.koobietech.eas.mbg.model.EasEduClass;
import com.koobietech.eas.mbg.model.EasEduSubjects;
import com.koobietech.eas.service.EasEduClassService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

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

@RestController
@Tag(name = "班级控制器")
public class EasEduClassController {

    @Resource
    EasEduClassService easEduClassService;

    /**
     * 添加班级类
     * @param easEduClass
     * @return
     */
    @PostMapping("/addClass")
    @Operation(summary = "增加班级类" , description = "用于增加班级类")
    public JsonResult addClass(@RequestBody  EasEduClass easEduClass){

        int add_i = easEduClassService.addClass(easEduClass);
        return JsonResult.ok("班级类添加成功");
    }

    /**
     * 修改班级类信息
     * @param easEduClass
     * @return
     */
    @PutMapping(value = "/updateClass")
    @Operation(summary = "更新班级类",description = "用于修改班级类信息")
    public JsonResult updateClass(@RequestBody EasEduClass easEduClass){
        int update_i = easEduClassService.updateClass(easEduClass);
        if (update_i > 0){
            return JsonResult.ok("修改成功！");
        }else {
            return JsonResult.fail("修改失败");
        }
    }

    /**
     * 删除班级类
     * @param id
     * @return
     */
    @DeleteMapping(value = "/deleteClass/{id}")
    @Operation(summary = "删除班级类",description = "用于根据 id 删除班级类")
    public JsonResult deleteClass(@PathVariable Long id ){
        int delete_i = easEduClassService.deleteClass(id);
        if (delete_i > 0){
            return JsonResult.ok();
        }else {
            return JsonResult.fail();
        }
    }

    /**
     * 通过 id 查询班级类
     * @param id
     * @return
     */
    @GetMapping(value = "/selectId")
    @Operation(summary = "id 查询班级类" , description = "通过id查询班级类")
    public JsonResult selectId( Long id ){
        EasEduClass easEduClass = easEduClassService.selectId(id);
        System.out.println(
                Disabled.valueOf(easEduClass.getDisabled())
        );
        return JsonResult.data(easEduClass);
    }

    /**
     * 查询所有的班级类
     * @return
     */
    @GetMapping(value = "/selectTotal")
    @Operation(summary = "查询所有的班级类",description = "用于查询所有的班级类")
    public JsonResult selectTotal(){
        List<EasEduClass> easEduClasses = easEduClassService.selectTotal();
        return JsonResult.data(easEduClasses);
    }

    /**
     * 通过条件查询班级类
     * @param easEduClass
     * @param pageNum
     * @param pageSize
     * @return
     */
    @PostMapping(value = "/selectCondition")
    @Operation(summary = "根据条件进行查询班级类", description = "用于根据条件查询班级类")
    public JsonPageResult selectCondition(@RequestBody EasEduClass easEduClass,
                                            @RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        PageData data = easEduClassService.selectCondition(easEduClass);
        return JsonPageResult.data(data);
    }
}
