package com.hzs.sale.order.controller.api;

import com.hzs.common.core.annotation.RepeatSubmit;
import com.hzs.common.core.constant.msg.MemberMsgConstants;
import com.hzs.common.core.web.domain.AjaxResult;
import com.hzs.common.core.utils.TransactionUtils;
import com.hzs.sale.order.controller.ParentOrderController;
import com.hzs.sale.order.param.OrderParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 新人礼包领取礼包
 */
@RestController
@RequestMapping("/api/order")
@Slf4j
public class ApiGiftSaOrderController extends ParentOrderController {

    /**
     * 确认注册订单，生成待支付订单,只有注册订单有待支付订单
     *
     * @param orderParam 订单参数
     */
    @PostMapping("/confirm-gift-order")
    @RepeatSubmit
    public AjaxResult confirmRegisterOrder(@RequestBody OrderParam orderParam) {
        initSecurityOrderParam(orderParam);
        // 查询新人礼包方案
        if (!checkPeopleRecMsgBoolean(orderParam)) {
            return AjaxResult.error(TransactionUtils.getContent(MemberMsgConstants.REQUIRED_NOT_EMPTY));
        }
        getOrderService().confirmNewPeopleGift(orderParam);
        return AjaxResult.success(orderParam);
    }

    private Boolean checkPeopleRecMsgBoolean(OrderParam orderParam) {
        return orderParam.getPkNewPeople() != null && orderParam.getRecPhone() != null && orderParam.getRecName() != null
                && orderParam.getRecName() != null && orderParam.getRecPhone() != null
                && orderParam.getRecProvince() != null && orderParam.getRecCity() != null;
    }
}
