package com.younike.member;

import com.younike.common.core.controller.BaseController;
import com.younike.common.core.domain.AjaxResult;
import com.younike.common.utils.StringUtils;
import com.younike.framework.config.AnonymousAccess;
import com.younike.hlpay.dto.OrderParam;
import com.younike.system.service.IServerTimeService;
import com.younike.system.service.IServerUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 服务人员Controller
 *
 * @author elev
 * @date 2022-01-06
 */
@Api("服务人员接口")
@RestController
@RequestMapping("/member/server")
public class MemberServerController extends BaseController {

    @Autowired
    private IServerUserService serverUserService;

    @Autowired
    private IServerTimeService serverTimeService;

    @ApiOperation("查询服务人员的服务时间")
    @AnonymousAccess
    @GetMapping("{serverId}")
    public AjaxResult getServerTime(@PathVariable("serverId") Long serverId) {
        if(ObjectUtils.isEmpty(serverId)){
            return AjaxResult.error("参数错误");
        }
        return AjaxResult.success(serverTimeService.getServerTime(serverId));
    }

    @ApiOperation("查询服务人员已经被预约的时间")
    @AnonymousAccess
    @GetMapping("order/{serverId}")
    public AjaxResult getServerOrderTime(@PathVariable("serverId") Long serverId) {
        if(ObjectUtils.isEmpty(serverId)){
            return AjaxResult.error("参数错误");
        }
        return AjaxResult.success(serverTimeService.getServerOrderTime(serverId));
    }

    @ApiOperation("查询预约的时间服务人员是否下班")
    @AnonymousAccess
    @GetMapping("getServerWork")
    public AjaxResult getServerWork(@RequestBody OrderParam param) {
        if(ObjectUtils.isEmpty(param)){
            return AjaxResult.error("参数错误");
        }
        //预约开始时间，结束时间不能为空
        if(StringUtils.isNull(param.getAppointmentStartTime()) || param.getSingleTime()==null ||param.getGoodsCounts()==null ||param.getServerId()==null ){
            return AjaxResult.error("参数错误(预约起始,单次服务时间,服务数量,服务人员id不能为空)");
        }

        return serverTimeService.getServerWork(param);
    }

}
