/*
 *      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.groupon.vo;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import io.swagger.annotations.ApiModelProperty;
import org.springblade.modules.api.response.GrouponOrderResponse;
import org.springblade.modules.groupon.entity.Groupon;
import lombok.Data;
import lombok.EqualsAndHashCode;
import io.swagger.annotations.ApiModel;
import org.springblade.modules.groupon.entity.GrouponGoods;
import org.springblade.modules.groupon.entity.GrouponUser;
import org.springblade.modules.groupon.entity.SelfTake;
import org.springblade.modules.mall.entity.GoodsInfo;
import org.springblade.modules.mall.vo.GoodsInfoVO;

import javax.validation.constraints.NotEmpty;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * 团购表视图实体类
 *
 * @author BladeX
 * @since 2023-06-02
 */
@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "GrouponVO对象", description = "团购表")
public class GrouponVO extends Groupon {
	private static final long serialVersionUID = 1L;

	@ApiModelProperty("轮播图")
	private List<String> slideshow;

	private int slideshowTotal;

	@ApiModelProperty("团购详情图")
	private List<String> detailImage;

	@ApiModelProperty("商品图片")
	private List<String> goodsImage;

	@ApiModelProperty("商品列表")
	private List<GoodsInfoVO> goodsList;

	@ApiModelProperty("拼团商品列表")
	private List<GrouponGoods> grouponGoodsList;

	@ApiModelProperty("商品总数")
	private Integer goodsTotal;

	@ApiModelProperty("拼团用户")
	private List<GrouponUser> grouponUsers;

	@ApiModelProperty("拼团用户总数")
	private Integer grouponUserTotal;

	@ApiModelProperty("发布时间描述")
	private String publishTimeDesc;

	@ApiModelProperty("团购状态描述")
	private String grouponStateDesc;

	@ApiModelProperty("自提点地址")
	private SelfTakeVO selfTake;

	@ApiModelProperty("自提点集合")
	private List<SelfTakeVO> selfTakeList;

	private BigDecimal maxPrice;

	private BigDecimal minPrice;

	private Boolean isStart;

	private Boolean isEnd;

	private long seconds;

	private long secondsStart;

//	@NotEmpty(message = "请选择自提点")
	@ApiModelProperty("自提点id集合")
	private List<Long> selfTakeIds;

//	@NotEmpty(message = "请选择商品")
	@ApiModelProperty("商品id集合")
	private List<Long> goodsIds;


	private String grouponStartTimeStr;
	/**
	 * 团购结束时间
	 */
	private String grouponEndTimeStr;

	/**
	 * 取货开始时间
	 */
	private String takeStartTimeStr;
	/**
	 * 取货结束时间
	 */
	private String takeEndTimeStr;

	/**
	 * 团购业务状态描述
	 */
	private String grouponBizStateDesc;

	/**
	 * 全部订单数量
	 */
	private int allOrderNum = 0;

	/**
	 * 网点订单数量
	 */
	private int dotOrderNum = 0;

	/**
	 * 团购订单数据
	 */
	private List<GrouponOrderResponse> grouponOrderList;

	public String getGrouponBizStateDesc() {
		return grouponBizStateDesc;
	}

	public String getGrouponStartTimeStr() {
		return getGrouponStartTime() == null ? "" : LocalDateTimeUtil.format(getGrouponStartTime(), "MM/dd HH:mm");
	}

	public String getGrouponEndTimeStr() {
		return getGrouponEndTime() == null ? "" : LocalDateTimeUtil.format(getGrouponEndTime(), "MM/dd HH:mm");
	}

	public String getTakeStartTimeStr() {
		return getTakeStartTime() == null ? "" : LocalDateTimeUtil.format(getTakeStartTime(), "MM/dd HH:mm");
	}

	public String getTakeEndTimeStr() {
		return getTakeEndTime() == null ? "" : LocalDateTimeUtil.format(getTakeEndTime(), "MM/dd HH:mm");
	}

	public Integer getGrouponUserTotal() {
		if (CollUtil.isNotEmpty(grouponUsers)) {
			Set<Long> collect = grouponUsers.stream().map(GrouponUser::getUserId).collect(Collectors.toSet());
			return collect.size();
		}
		return 0;
	}

	public int getSlideshowTotal() {
		return slideshow == null ? 0 : slideshow.size();
	}
}
