package cn.iocoder.yudao.module.server.controller.admin.workorderLog;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.server.controller.admin.workorderType.vo.WorkorderTypeListReqVO;
import cn.iocoder.yudao.module.server.controller.admin.workorderType.vo.WorkorderTypeRespVO;
import cn.iocoder.yudao.module.server.controller.admin.workorderType.vo.WorkorderTypeSaveReqVO;
import cn.iocoder.yudao.module.server.dal.dataobject.workorderLog.WorkorderLogDO;
import cn.iocoder.yudao.module.server.dal.dataobject.workorderLog.WorkorderLogVO;
import cn.iocoder.yudao.module.server.dal.dataobject.workorderType.WorkorderTypeDO;
import cn.iocoder.yudao.module.server.service.workorderLog.WorkorderLogService;
import cn.iocoder.yudao.module.server.service.workorderType.WorkorderTypeService;
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptRespVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 工单日志")
@RestController
@RequestMapping("/server/workorder-log")
@Validated
public class WorkorderLogController {

    @Resource
    private WorkorderLogService workorderLogService;

    @PostMapping("/create")
    @Operation(summary = "创建工单日志")
    @PreAuthorize("@ss.hasPermission('server:workorder-type:create')")
    public CommonResult<Long> createWorkorderType(@Valid @RequestBody WorkorderLogDO workorderLogDO) {
        return success(workorderLogService.createWorkorderLog(workorderLogDO));
    }

//    @PostMapping("/update")
//    @Operation(summary = "更新工单类型")
//    @PreAuthorize("@ss.hasPermission('server:workorder-type:update')")
//    public CommonResult<Boolean> updateWorkorderType(@Valid @RequestBody WorkorderTypeSaveReqVO updateReqVO) {
//        workorderLogService.updateWorkorderType(updateReqVO);
//        return success(true);
//    }
//
//    @PostMapping("/delete")
//    @Operation(summary = "删除工单类型")
//    @Parameter(name = "id", description = "编号", required = true)
//    @PreAuthorize("@ss.hasPermission('server:workorder-type:delete')")
//    public CommonResult<Boolean> deleteWorkorderType(@RequestParam("id") Long id) {
//        workorderLogService.deleteWorkorderType(id);
//        return success(true);
//    }
//
//    @GetMapping("/get")
//    @Operation(summary = "获得工单类型")
//    @Parameter(name = "id", description = "编号", required = true, example = "1024")
//    @PreAuthorize("@ss.hasPermission('server:workorder-type:query')")
//    public CommonResult<WorkorderTypeRespVO> getWorkorderType(@RequestParam("id") Long id) {
//        WorkorderTypeDO workorderType = workorderLogService.getWorkorderType(id);
//        return success(BeanUtils.toBean(workorderType, WorkorderTypeRespVO.class));
//    }
//
    @GetMapping("/list")
    @Operation(summary = "获得工单日志列表")
    @PreAuthorize("@ss.hasPermission('server:workorder-type:query')")
    public CommonResult<List<WorkorderLogVO>> getWorkorderLogList(@Valid Long workorderId) {
        List<WorkorderLogVO> list = workorderLogService.getWorkorderLogList(workorderId);
        return success(list);
    }

    @GetMapping("/reject-list")
    @Operation(summary = "获得驳回列表")
    @PreAuthorize("@ss.hasPermission('server:workorder-type:query')")
    public CommonResult<List<DeptRespVO>> getRejectList(@Valid Long workorderId) {
        List<DeptRespVO> list = workorderLogService.getRejectList(workorderId);
        return success(list);
    }
}