package com.ruoyi.api.controller.info;

import com.ruoyi.api.controller.common.AbstractApiController;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.FilePathSplicingType;
import com.ruoyi.common.filepathsplicing.FilePathSplicing;
import com.ruoyi.info.order.domain.bo.OrderBo;
import com.ruoyi.info.order.domain.vo.OrderVo;
import com.ruoyi.info.order.service.IOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * 订单Controller
 *
 * @author ruoyi
 * @date 2025-09-20
 */
@Validated
@Api(value = "护工端订单控制器", tags = {"护工端订单管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/worker/order")
public class ApiWorkerOrderController extends AbstractApiController {

    private final IOrderService iOrderService;

    /**
     * 分页查询订单列表
     */
    @FilePathSplicing(type = FilePathSplicingType.RESPONSE)
    @ApiOperation("查询订单列表")
    @GetMapping("/page")
    public TableDataInfo<OrderVo> page(@Validated(QueryGroup.class) OrderBo bo, PageQuery pageQuery) {
        bo.setWorkerId(getWorkerId());
        return iOrderService.queryPageList(bo, pageQuery);
    }

    /**
     * 获取订单详细信息
     */
    @FilePathSplicing(type = FilePathSplicingType.RESPONSE)
    @ApiOperation("获取订单详细信息")
    @GetMapping("/info/{id}")
    public R<OrderVo> getInfo(@ApiParam("主键")
                                                  @NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return R.ok(iOrderService.queryById(id));
    }

    @ApiOperation("开始服务")
    @RepeatSubmit()
    @PostMapping("/startService/{id}")
    public R<Void> startService(@ApiParam("主键")
                              @NotNull(message = "主键不能为空")
                              @PathVariable("id") Long id) {
        return toAjax(iOrderService.startService(id, getWorkerId()) ? 1 : 0);
    }

    @ApiOperation("完成服务")
    @RepeatSubmit()
    @PostMapping("/finishService/{id}")
    public R<Void> finishService(@ApiParam("主键")
                                     @NotNull(message = "主键不能为空")
                                     @PathVariable("id") Long id) {
        return toAjax(iOrderService.finishService(id, getWorkerId()) ? 1 : 0);
    }

    @ApiOperation("获取管理老师电话")
    @GetMapping("/getManagerPhone/{id}")
    public R<String> getManagerPhone(@ApiParam("主键")
                                         @NotNull(message = "主键不能为空")
                                         @PathVariable("id") Long id) {
        return R.ok(iOrderService.getManagerPhone(id, getWorkerId()));
    }
}
