package com.ruoyi.web.modules.farming.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.farming.domain.BizServiceAppointmentReview;
import com.ruoyi.web.modules.farming.service.IBizExpertMyAppointmentService;

/**
 * 我的预约（专家）
 */
@RestController
@RequestMapping("/techService/myAppointment/expert")
public class BizExpertMyAppointmentController extends BaseController
{
    @Autowired
    private IBizExpertMyAppointmentService bizExpertMyAppointmentService;

    @PreAuthorize("@ss.hasPermi('techService:expertMyAppointment:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizServiceAppointment query)
    {
        startPage();
        List<BizServiceAppointment> list = bizExpertMyAppointmentService.selectExpertAppointmentList(query,
                SecurityUtils.getUserId());
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('techService:expertMyAppointment:query')")
    @Log(title = "我的预约（专家）查看详情", businessType = BusinessType.OTHER)
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizExpertMyAppointmentService.selectExpertAppointmentById(id, SecurityUtils.getUserId()));
    }

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

    @PreAuthorize("@ss.hasPermi('techService:expertMyAppointment: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(bizExpertMyAppointmentService.reject(id, rejectReason, SecurityUtils.getUserId(), getUsername()));
    }

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

    @PreAuthorize("@ss.hasPermi('techService:expertMyAppointment:reviewList')")
    @Log(title = "我的预约（专家）查看评价", businessType = BusinessType.OTHER)
    @GetMapping("/reviewList/{id}")
    public AjaxResult reviewList(@PathVariable("id") Long id)
    {
        List<BizServiceAppointmentReview> list =
                bizExpertMyAppointmentService.selectReviewList(id, SecurityUtils.getUserId());
        return success(list);
    }
}
