package com.srs.web.controller.dormitory;

import com.srs.common.core.controller.BaseController;
import com.srs.common.core.domain.AjaxResult;
import com.srs.common.core.domain.R;
import com.srs.common.core.page.TableDataInfo;
import com.srs.dormitory.domain.Dto.*;
import com.srs.dormitory.domain.Vo.RepairListVo;
import com.srs.dormitory.service.IDmsRepairRecordsService;
import com.srs.dormitory.service.IDmsRepairStatusService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 * 维修记录表 前端控制器
 * </p>
 *
 * @author 猪油骨
 * @since 2023-08-04
 */
@RestController
@RequestMapping("/dormitory/dms-repair-records")
@AllArgsConstructor
@Api(tags = "宿舍报修")
public class DmsRepairRecordsController extends BaseController {
    private final IDmsRepairRecordsService repairRecordsService;
    private final IDmsRepairStatusService statusService;


    @PostMapping("/add")
    @ApiOperation("学生填写维修申请")
//    @PreAuthorize("@ss.hasPermi('dormitory:records:addRepair')")
    public AjaxResult addRepair(@Validated @RequestBody AddRepairDto addRepairDto) {

        return repairRecordsService.addRepair(addRepairDto);
    }

    @PostMapping("/audit")
    @ApiOperation("管理员审核并分配对象")
//    @PreAuthorize("@ss.hasPermi('dormitory:records:audit')")
    public AjaxResult audit(@Validated @RequestBody AuditDto auditDto) {
        return repairRecordsService.audit(auditDto);
    }

    @PostMapping("/repair")
    @ApiOperation("师傅更改维修状态")
//    @PreAuthorize("@ss.hasPermi('dormitory:records:repair')")
    public AjaxResult repair(@Validated @RequestBody RepairDto dto) {
        return repairRecordsService.repair(dto);
    }

    @PostMapping("/assess")
    @ApiOperation("学生评价")
//    @PreAuthorize("@ss.hasPermi('dormitory:records:assess')")
    public AjaxResult assess(@Validated @RequestBody AssessDto dto) {
        return repairRecordsService.assess(dto);
    }

    @PostMapping("/appraise")
    @ApiOperation("管理员开启关闭评价")
//    @PreAuthorize("@ss.hasPermi('dormitory:records:appraise')")
    public AjaxResult appraise(@RequestParam boolean isAppraise) {
        return repairRecordsService.appraise(isAppraise);
    }

    @PostMapping("/cancel")
    @ApiOperation("取消维修")
//    @PreAuthorize("@ss.hasPermi('dormitory:records:cancel')")
    public AjaxResult cancel(@RequestParam Long id, @RequestParam(required = false) String reason) {
        return repairRecordsService.cancel(id, reason);
    }

    @GetMapping("/repairList")
    @ApiOperation("查看维修列表")
    public TableDataInfo repairList(@Validated RepairListVo dto) {
        return getDataTable(repairRecordsService.repairList(dto));
    }

    @GetMapping("/repairInfo")
    @ApiOperation("维修单详情")
    public AjaxResult repairInfo(Long id) {
        return repairRecordsService.repairInfo(id);
    }

    @GetMapping("/repairStatus")
    @ApiOperation("维修状态追踪")
    public TableDataInfo repairStatus(@Validated @NotNull(message = "repairId不能为null") Long repairId) {
        return getDataTable(statusService.repairStatus(repairId));
    }

    @PostMapping("delete")
    @ApiOperation("批量删除订单")
//    @PreAuthorize("@ss.hasPermi('dormitory:records:delete')")
    public AjaxResult delete(@Validated @NotNull(message = "id列表不能为null") @RequestBody List<Long> ids) {
        return repairRecordsService.delete(ids);
    }


    @PostMapping("delete/{id}")
    @ApiOperation("根据id删除订单")
//    @PreAuthorize("@ss.hasPermi('dormitory:records:deleteById')")
    public AjaxResult deleteById(@PathVariable Long id) {
        return repairRecordsService.deleteById(id);
    }


}
