/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.mall.vo;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import io.swagger.annotations.ApiModelProperty;
import org.springblade.common.enums.BusinessSceneEnum;
import org.springblade.modules.mall.entity.CouponUser;
import lombok.Data;
import lombok.EqualsAndHashCode;
import io.swagger.annotations.ApiModel;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 用户优惠券关联表视图实体类
 *
 * @author BladeX
 * @since 2023-05-04
 */
@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "CouponUserVO对象", description = "用户优惠券关联表")
public class CouponUserVO extends CouponUser {
	private static final long serialVersionUID = 1L;

	/**
	 * 优惠券优惠的类型;1-折扣券 2-满减券
	 */
	@ApiModelProperty(value = "优惠券优惠的类型;1-折扣券 2-满减券")
	private Integer preferentialType;
	/**
	 * 优惠券类型;1-平台 2-商家 3-商品
	 */
	@ApiModelProperty(value = "优惠券类型;1-平台 2-商家 3-商品")
	private Integer type;
	@ApiModelProperty(value = "业务场景;1-新人福利 2-福利中心 3-其他")
	private Integer businessScene;
	@ApiModelProperty(value = "有效天数")
	private Integer validDays;
	/**
	 * 优惠券名称
	 */
	@ApiModelProperty(value = "优惠券名称")
	private String title;
	/**
	 * 开始使用时间
	 */
	@ApiModelProperty(value = "开始使用时间")
	private LocalDateTime startTime;
	/**
	 * 结束使用时间
	 */
	@ApiModelProperty(value = "结束使用时间")
	private LocalDateTime endTime;
	/**
	 * 折扣比例
	 */
	@ApiModelProperty(value = "折扣比例")
	private Double discountRatio;
	/**
	 * 满减金额
	 */
	@ApiModelProperty(value = "满减金额")
	private BigDecimal fullReduction;
	/**
	 * 优惠金额
	 */
	@ApiModelProperty(value = "优惠金额")
	private BigDecimal discountAmount;

	public LocalDateTime getStartTime() {
		if (BusinessSceneEnum.NEW.getValue().equals(this.businessScene)) {
			return LocalDateTimeUtil.parse(DateUtil.format(super.getCreateTime(), "yyyy-MM-dd 00:00:00"), "yyyy-MM-dd 00:00:00");
		}
		return startTime;
	}

	public LocalDateTime getEndTime() {
		if (BusinessSceneEnum.NEW.getValue().equals(this.businessScene)) {
			String format = LocalDateTimeUtil.format(this.getStartTime().plusDays(this.validDays).plusHours(23).plusMinutes(59).plusSeconds(59), "yyyy-MM-dd 23:59:59");
			return LocalDateTimeUtil.parse(format, "yyyy-MM-dd HH:mm:ss");
		}
		return endTime;
	}
}
