package org.jeecg.modules.api.teambuyController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.apiBean.PageBean;
import org.jeecg.modules.apiService.OrderService;
import org.jeecg.modules.teambuyOrderGoods.entity.TeambuyOrderGoods;
import org.jeecg.modules.teambuyOrderLeader.entity.TeambuyOrderLeader;
import org.jeecg.modules.teambuyOrderMember.entity.TeambuyOrderMember;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags="订单-订单信息相关接口")
@RestController
@RequestMapping("/teambuy/order")
@Slf4j
public class OrderController {
    /******************************************************************************************************************/
    //订单
    @Resource
    private OrderService orderService;
    /******************************************************************************************************************/

    //查看团餐订单列表
    @ApiOperation(value="订单-查询团餐订单列表/详情", notes="status：0-待出餐 1-已出餐 2-待取餐 3-已完成")
    @RequestMapping(value = "/queryLeaderOrderList", method = {RequestMethod.GET})
    public Result<?> queryLeaderOrderList(@RequestHeader("X-Access-Token") String token, TeambuyOrderLeader teambuyOrderLeader, PageBean pageBean){
        return orderService.queryLeaderOrderList(token, teambuyOrderLeader, pageBean);
    }
    //根据团餐id查询团团员订单列表
    @ApiOperation(value="订单-根据团餐id查询团团员订单列表", notes="status：0-待支付 1-待出餐 2-送餐中 3-待取餐 4-已完成")
    @RequestMapping(value = "/queryLeaderOrderListById", method = {RequestMethod.GET})
    public Result<?> queryLeaderOrderListById(@RequestHeader("X-Access-Token") String token, String teambuyOrderLeaderId, PageBean pageBean){
        return orderService.queryLeaderOrderListById(token, teambuyOrderLeaderId, pageBean);
    }

    //查看团员订单列表
    @ApiOperation(value="订单-查看团员订单列表/详情", notes="status：0-待支付 1-待出餐 2-送餐中 3-待取餐 4-已完成")
    @RequestMapping(value = "/queryMemberOrderList", method = {RequestMethod.GET})
    public Result<?> queryMemberOrderList(@RequestHeader("X-Access-Token") String token, TeambuyOrderMember teambuyOrderMember, PageBean pageBean){
        return orderService.queryMemberOrderList(token, teambuyOrderMember, pageBean);
    }

    //团长通知取餐
    @ApiOperation(value="订单-团长通知全体团员取餐", notes="订单-团长通知全体团员取餐")
    @RequestMapping(value = "/informOrderAll", method = {RequestMethod.POST})
    public Result<?> informOrderAll(@RequestHeader("X-Access-Token") String token, String leaderOrderId){
        return orderService.informOrderAll(token, leaderOrderId);
    }

    //团长完成取餐
    @ApiOperation(value="订单-团长完成全体取餐", notes="订单-团长完成全体取餐")
    @RequestMapping(value = "/finishOrderAll", method = {RequestMethod.POST})
    public Result<?> finishOrderAll(@RequestHeader("X-Access-Token") String token, String leaderOrderId){
        return orderService.finishOrderAll(token, leaderOrderId);
    }

    //团长通知取餐
    @ApiOperation(value="订单-团长通知单体取餐", notes="订单-团长通知单体取餐")
    @RequestMapping(value = "/informOrderOne", method = {RequestMethod.POST})
    public Result<?> informOrderOne(@RequestHeader("X-Access-Token") String token, String memberOrderId){
        return orderService.informOrderOne(token, memberOrderId);
    }

    //团长完成取餐
    @ApiOperation(value="订单-团长完成单体取餐", notes="订单-团长完成单体取餐")
    @RequestMapping(value = "/finishOrderOne", method = {RequestMethod.POST})
    public Result<?> finishOrderOne(@RequestHeader("X-Access-Token") String token, String memberOrderId){
        return orderService.finishOrderOne(token, memberOrderId);
    }

    //修改团长订单状态
    @ApiOperation(value="订单-修改团长订单状态", notes="订单-修改团长订单状态")
    @RequestMapping(value = "/updateLeaderOrderById", method = {RequestMethod.POST})
    public Result<?> updateLeaderOrderById(@RequestHeader("X-Access-Token") String token, TeambuyOrderLeader teambuyOrderLeader){
        return orderService.updateLeaderOrderById(token, teambuyOrderLeader);
    }

    //修改团员订单状态
    @ApiOperation(value="订单-修改团员订单状态", notes="订单-修改团员订单状态")
    @RequestMapping(value = "/updateMemberOrderById", method = {RequestMethod.POST})
    public Result<?> updateMemberOrderById(@RequestHeader("X-Access-Token") String token, TeambuyOrderMember teambuyOrderMember){
        return orderService.updateMemberOrderById(token, teambuyOrderMember);
    }

    //团员完成取餐
    @ApiOperation(value="订单-团员完成取餐", notes="订单-团员完成取餐")
    @RequestMapping(value = "/finishMemberOrderById", method = {RequestMethod.POST})
    public Result<?> finishMemberOrderById(@RequestHeader("X-Access-Token") String token, String memberOrderId){
        return orderService.finishMemberOrderById(token, memberOrderId);
    }

//    //创建订单
//    @ApiOperation(value="订单-创建订单", notes="支付方式(payType)：0-微信支付 1-余额支付")
//    @RequestMapping(value = "/createOrder", method = {RequestMethod.POST})
//    public Result<?> createOrder(@RequestHeader("X-Access-Token") String token, TeambuyOrderMember teambuyOrderMember, String payType){
//        return orderService.createOrder(token, teambuyOrderMember, payType);
//    }
    //创建订单
    @ApiOperation(value="订单-创建订单", notes="支付方式(payType)：0-微信支付 1-余额支付")
    @RequestMapping(value = "/createOrder", method = {RequestMethod.POST})
    public Result<?> createOrder(@RequestHeader("X-Access-Token") String token, TeambuyOrderMember teambuyOrderMember, String leaderId, String goodss, String userCouponId){
        return orderService.createOrder2(token, teambuyOrderMember, leaderId, goodss, userCouponId);
    }

    //修改团员订单状态
    @ApiOperation(value="订单-取消团员订单", notes="订单-修改团员订单")
    @RequestMapping(value = "/deleteMemberOrderById", method = {RequestMethod.POST})
    public Result<?> deleteMemberOrderById(@RequestHeader("X-Access-Token") String token, String memberOrderId){
        return orderService.deleteMemberOrderById(token, memberOrderId);
    }

    //支付订单
    @ApiOperation(value="订单-支付订单", notes="支付方式(payType)：0-微信支付 1-余额支付")
    @RequestMapping(value = "/payOrder", method = {RequestMethod.POST})
    public Result<?> payOrder(@RequestHeader("X-Access-Token") String token, String orderId, String payType){
        return orderService.payOrder(token, orderId, payType);
    }

    //支付回调
    @PostMapping("/payOrderNotify")
    public Object payOrderNotify(@RequestBody String requestBody){
        return orderService.payOrderNotify(requestBody);
    }
}
