package com.bonus.canteen.core.marketing.v2.rule.param;

import com.bonus.common.houqin.constant.LeConstants;
import com.bonus.canteen.core.customer.constants.CustAgeEnum;
import com.bonus.canteen.core.customer.model.CustInfo;
import com.bonus.canteen.core.marketing.v2.constants.MarketModuleTypeEnum;
import com.bonus.canteen.core.marketing.v2.constants.MarketSceneTypeEnum;
import com.bonus.canteen.core.marketing.v2.param.MarketRuleDeviceParam;
import com.bonus.canteen.core.marketing.v2.rule.pay.dto.RulePayComputeDTO;
import com.bonus.canteen.core.marketing.v2.rule.price.dto.RulePriceOrderDTO;
import com.bonus.canteen.core.marketing.v2.rule.price.dto.RulePriceResultOrderDTO;
import com.bonus.canteen.core.marketing.v2.rule.recharge.dto.RuleRechargeComputeDTO;
import com.bonus.canteen.core.marketing.v2.util.MarketUtil;
import com.bonus.canteen.core.order.common.constants.OrderTypeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Objects;

@ApiModel("查询匹配规则入参")
public class RuleRangeParam {
   @ApiModelProperty("场景类型")
   private Integer sceneType;
   @ApiModelProperty("模块类型（1：就餐，2：计价，3：扣款，4：充值）")
   private Integer moduleType;
   @ApiModelProperty("食堂id")
   private Long canteenId;
   @ApiModelProperty("档口id")
   private Long stallId;
   @ApiModelProperty("设备sn")
   private String deviceSn;
   @ApiModelProperty("餐次id")
   private Integer mealtimeType;
   @ApiModelProperty("部门id")
   private Long orgId;
   @ApiModelProperty("人员类别")
   private Integer psnType;
   @ApiModelProperty("适用年龄段")
   private Integer ageType;
   @ApiModelProperty("支付渠道")
   private Integer payChannel;
   @ApiModelProperty("交易日期")
   private LocalDate tradeDate;
   @ApiModelProperty("下单时间")
   private LocalDateTime orderTime;

   public static RuleRangeParam ruleMealRangeParam(RulePriceOrderDTO order, CustInfo custInfo, Integer verifyFlag) {
      RuleRangeParam ruleRangeParam = new RuleRangeParam();
      ruleRangeParam.setModuleType(MarketModuleTypeEnum.RULE_MEAL.getKey());
      ruleRangeParam.setTradeDate(order.getOrderDate());
      ruleRangeParam.setOrderTime(order.getOrderTime());
      ruleRangeParam.setDeviceSn(LeConstants.COMMON_YES.equals(verifyFlag) ? MarketUtil.formatDevice(order.getCanteenId(), order.getStallId(), order.getDeviceSn()) : MarketUtil.formatDeviceSn(order.getOrderType(), order.getCanteenId(), order.getStallId(), order.getDeviceSn()));
      return ruleRangeParam;
   }

   public static RuleRangeParam rulePriceRangeParam(RulePriceResultOrderDTO order, CustInfo custInfo) {
      RuleRangeParam ruleRangeParam = new RuleRangeParam();
      ruleRangeParam.setModuleType(MarketModuleTypeEnum.RULE_PRICE.getKey());
      ruleRangeParam.setCanteenId(order.getCanteenId());
      ruleRangeParam.setStallId(order.getStallId());
      ruleRangeParam.setMealtimeType(order.getMealtimeType());
      ruleRangeParam.setTradeDate(order.getOrderDate());
      ruleRangeParam.setOrderTime(order.getOrderTime());
      ruleRangeParam.setDeviceSn(MarketUtil.formatDeviceSn(order.getOrderType(), order.getCanteenId(), order.getStallId(), order.getDeviceSn()));
      ruleRangeParam.setOrgId(custInfo.getOrgId());
      ruleRangeParam.setPsnType(custInfo.getPsnType());
      ruleRangeParam.setAgeType(CustAgeEnum.getEnumByAge(custInfo.getBirthday()).getKey());
      ruleRangeParam.setSceneType(MarketSceneTypeEnum.getSceneTypeByOrderType(order.getOrderType()).getKey());
      return ruleRangeParam;
   }

   public static RuleRangeParam rulePayRangeParam(RulePayComputeDTO computeDTO, CustInfo custInfo) {
      RuleRangeParam ruleRangeParam = new RuleRangeParam();
      ruleRangeParam.setModuleType(MarketModuleTypeEnum.RULE_PAY.getKey());
      ruleRangeParam.setTradeDate(Objects.nonNull(computeDTO.getConsumeDate()) ? computeDTO.getConsumeDate() : LocalDate.now());
      ruleRangeParam.setDeviceSn(MarketUtil.formatPayDeviceSn(computeDTO.getOrderType(), computeDTO.getCanteenId(), computeDTO.getDeviceSn()));
      ruleRangeParam.setOrgId(custInfo.getOrgId());
      ruleRangeParam.setPsnType(custInfo.getPsnType());
      ruleRangeParam.setAgeType(CustAgeEnum.getEnumByAge(custInfo.getBirthday()).getKey());
      ruleRangeParam.setOrderTime(LocalDateTime.now());
      return ruleRangeParam;
   }

   public static RuleRangeParam ruleRechargeRangeParam(RuleRechargeComputeDTO computeDTO, CustInfo custInfo) {
      RuleRangeParam ruleRangeParam = new RuleRangeParam();
      ruleRangeParam.setModuleType(MarketModuleTypeEnum.RULE_RECHARGE.getKey());
      ruleRangeParam.setTradeDate(computeDTO.getTradeDate());
      ruleRangeParam.setPayChannel(computeDTO.getPayChannel());
      ruleRangeParam.setOrgId(custInfo.getOrgId());
      ruleRangeParam.setPsnType(custInfo.getPsnType());
      ruleRangeParam.setAgeType(CustAgeEnum.getEnumByAge(custInfo.getBirthday()).getKey());
      ruleRangeParam.setOrderTime(LocalDateTime.now());
      return ruleRangeParam;
   }

   public static RuleRangeParam ruleDeviceRangeParam(MarketRuleDeviceParam param) {
      RuleRangeParam ruleRangeParam = new RuleRangeParam();
      ruleRangeParam.setModuleType(MarketModuleTypeEnum.RULE_PRICE.getKey());
      ruleRangeParam.setCanteenId(param.getCanteenId());
      ruleRangeParam.setStallId(param.getStallId());
      ruleRangeParam.setMealtimeType(param.getMealtimeType());
      ruleRangeParam.setTradeDate(param.getOrderDate());
      ruleRangeParam.setOrderTime(LocalDateTime.now());
      ruleRangeParam.setDeviceSn(MarketUtil.formatDeviceSn(OrderTypeEnum.ANDROID.getKey(), param.getCanteenId(), param.getStallId(), param.getDeviceSn()));
      ruleRangeParam.setOrgId(param.getOrgId());
      ruleRangeParam.setPsnType(param.getPsnType());
      ruleRangeParam.setAgeType(param.getAgeType());
      ruleRangeParam.setSceneType(MarketSceneTypeEnum.SCENE_DEFAULT.getKey());
      return ruleRangeParam;
   }

   public Integer getSceneType() {
      return this.sceneType;
   }

   public Integer getModuleType() {
      return this.moduleType;
   }

   public Long getCanteenId() {
      return this.canteenId;
   }

   public Long getStallId() {
      return this.stallId;
   }

   public String getDeviceSn() {
      return this.deviceSn;
   }

   public Integer getMealtimeType() {
      return this.mealtimeType;
   }

   public Long getOrgId() {
      return this.orgId;
   }

   public Integer getPsnType() {
      return this.psnType;
   }

   public Integer getAgeType() {
      return this.ageType;
   }

   public Integer getPayChannel() {
      return this.payChannel;
   }

   public LocalDate getTradeDate() {
      return this.tradeDate;
   }

   public LocalDateTime getOrderTime() {
      return this.orderTime;
   }

   public void setSceneType(final Integer sceneType) {
      this.sceneType = sceneType;
   }

   public void setModuleType(final Integer moduleType) {
      this.moduleType = moduleType;
   }

   public void setCanteenId(final Long canteenId) {
      this.canteenId = canteenId;
   }

   public void setStallId(final Long stallId) {
      this.stallId = stallId;
   }

   public void setDeviceSn(final String deviceSn) {
      this.deviceSn = deviceSn;
   }

   public void setMealtimeType(final Integer mealtimeType) {
      this.mealtimeType = mealtimeType;
   }

   public void setOrgId(final Long orgId) {
      this.orgId = orgId;
   }

   public void setPsnType(final Integer psnType) {
      this.psnType = psnType;
   }

   public void setAgeType(final Integer ageType) {
      this.ageType = ageType;
   }

   public void setPayChannel(final Integer payChannel) {
      this.payChannel = payChannel;
   }

   public void setTradeDate(final LocalDate tradeDate) {
      this.tradeDate = tradeDate;
   }

   public void setOrderTime(final LocalDateTime orderTime) {
      this.orderTime = orderTime;
   }
}
