package com.ruoyi.web.modules.diagnosis.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.web.modules.diagnosis.domain.BizServiceAppointment;
import com.ruoyi.web.modules.diagnosis.domain.VetAppointmentRejectBody;
import com.ruoyi.web.modules.diagnosis.service.IBizVetMyAppointmentService;

/**
 * 我的预约（兽医）
 */
@RestController
@RequestMapping("/diseaseTreatment/myAppointment/vet")
public class BizVetMyAppointmentController extends BaseController
{
    @Autowired
    private IBizVetMyAppointmentService bizVetMyAppointmentService;

    @PreAuthorize("@ss.hasPermi('diseaseTreatment:vetMyAppointment:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizServiceAppointment query)
    {
        startPage();
        List<BizServiceAppointment> list = bizVetMyAppointmentService.selectVetAppointmentList(query,
                SecurityUtils.getUserId());
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('diseaseTreatment:vetMyAppointment:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizVetMyAppointmentService.selectVetAppointmentById(id, SecurityUtils.getUserId()));
    }

    @PreAuthorize("@ss.hasPermi('diseaseTreatment:vetMyAppointment:confirm')")
    @Log(title = "我的预约（兽医）确认接诊", businessType = BusinessType.UPDATE)
    @PostMapping("/confirm/{id}")
    public AjaxResult confirm(@PathVariable("id") Long id)
    {
        return toAjax(bizVetMyAppointmentService.confirm(id, SecurityUtils.getUserId(), getUsername()));
    }

    @PreAuthorize("@ss.hasPermi('diseaseTreatment:vetMyAppointment:reject')")
    @Log(title = "我的预约（兽医）拒绝接诊", businessType = BusinessType.UPDATE)
    @PostMapping("/reject/{id}")
    public AjaxResult reject(@PathVariable("id") Long id, @RequestBody(required = false) VetAppointmentRejectBody body)
    {
        String rejectReason = body != null ? body.getRejectReason() : null;
        return toAjax(bizVetMyAppointmentService.reject(id, rejectReason, SecurityUtils.getUserId(), getUsername()));
    }

    @PreAuthorize("@ss.hasPermi('diseaseTreatment:vetMyAppointment:complete')")
    @Log(title = "我的预约（兽医）完成接诊", businessType = BusinessType.UPDATE)
    @PostMapping("/complete/{id}")
    public AjaxResult complete(@PathVariable("id") Long id)
    {
        return toAjax(bizVetMyAppointmentService.complete(id, SecurityUtils.getUserId(), getUsername()));
    }
}
