package com.sqx.modules.orders.controller.app;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sqx.common.utils.PageUtils;
import com.sqx.common.utils.Result;
import com.sqx.modules.app.annotation.Login;
import com.sqx.modules.orders.entity.Orders;
import com.sqx.modules.orders.entity.PriceRule;
import com.sqx.modules.orders.service.OrdersService;
import com.sqx.modules.orders.service.PriceRuleService;
import com.sqx.modules.orders.vo.CalculatePrice;
import com.sqx.modules.tbCoupon.service.TbCouponUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@Api(value = "价格规则-用户端", tags = {"价格规则-用户端"})
@RequestMapping("/app/priceRule")
public class AppPriceRuleController {

    @Autowired
    private PriceRuleService priceRuleService;

    @GetMapping("/selectPriceRuleList")
    @ApiOperation("查询价格规则")
    public Result selectPriceRuleList(Integer peopleNum){
        List<PriceRule> priceRuleList = priceRuleService.list(new QueryWrapper<PriceRule>()
                .eq(peopleNum != null, "people_num", peopleNum).eq( "status", 1));
        return Result.success().put("data",priceRuleList);
    }

    @Login
    @PostMapping("/getOrdersPrice")
    @ApiOperation("查询订单价格")
    public Result getOrdersPrice(@RequestBody Orders orders){
        CalculatePrice ordersPrice = priceRuleService.getOrdersPrice(orders);
        if(ordersPrice==null){
            return Result.error("暂无当前方案！");
        }
        return Result.success().put("data",ordersPrice);
    }


}