package com.ads.business.controller;

import com.ads.business.service.DocTypeService;
import com.ads.business.service.model.request.DocTypeDetailRequest;
import com.ads.business.service.model.request.DocTypeEditRequest;
import com.ads.business.service.model.request.DocTypeListRequest;
import com.ads.business.service.model.request.UpdateSwitchRequest;
import com.ads.business.service.model.response.DocTypeDetailResponse;
import com.ads.common.data.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @Return
 * @Author hou
 * @Date 2021/10/25 13:05
 * @Destription 文件分类管理
 */
@RestController
@Api(tags = "文件分类管理")
@RequestMapping("/doc/type")
public class DocTypeController {

    @Resource
    private DocTypeService docTypeService;

    @GetMapping("/list")
    @ApiOperation("文件分类列表")
    public JsonResult list(DocTypeListRequest request){
        return docTypeService.selectList(request);
    }

    @PostMapping("/add")
    @ApiOperation("新增文件分类")
    JsonResult add(@RequestBody@Valid DocTypeEditRequest request){
        return docTypeService.add(request);
    }


    @GetMapping("/dropListAll")
    @ApiOperation("所有文件分类下拉列表")
    JsonResult dropListAll(){
        return docTypeService.dropListAll();
    }

    @PostMapping("/dropList")
    @ApiOperation("文件分类下拉列表")
    JsonResult dropList(){
        return docTypeService.dropList();
    }

    @PostMapping("/detail")
    @ApiOperation("文件分类详情")
    JsonResult<DocTypeDetailResponse> detail(@RequestBody DocTypeDetailRequest request){
        return docTypeService.detail(request);
    }

    /**
     * 状态修改
     *
     * @param request 修改状态入参
     * @return JsonResult
     */
    @PutMapping("/updateSwitch")
    @ApiOperation(value = "状态修改", notes = "状态修改")
    public JsonResult updateSwitch(@RequestBody @Valid UpdateSwitchRequest request) {
        return docTypeService.updateSwitch(Long.valueOf(request.getId()), request.getStatus());
    }

    @PostMapping("/update")
    @ApiOperation("修改文件分类")
    JsonResult update(@RequestBody@Valid DocTypeEditRequest request){
        return docTypeService.updateType(request);
    }
}
