package com.cyksj.model.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.cyksj.model.dto.CornMetaDto;
import com.cyksj.model.request.corp.Attachments;
import com.ejlchina.searcher.bean.DbIgnore;
import com.ejlchina.searcher.bean.SearchBean;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;

import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 企业微信群发消息任务
 * </p>
 *
 * @author zoujiajian
 * @since 2022-05-12
 */
@Data
@EqualsAndHashCode(callSuper = false)
@SearchBean(tables = "corp_msg_bulk_task",
		where = ":tag_id:")
public class CorpMsgBulkTask implements Serializable {

	@TableId(value = "id", type = IdType.AUTO)
	private Long id;

	/**
	 * 分类id
	 */
	@TableField(updateStrategy = FieldStrategy.IGNORED)
	private Long category;

	/**
	 * 分类名
	 */
	@TableField(exist = false)
	@DbIgnore
	private String categoryName;

	/**
	 * 企业微信id
	 */
	private Long wxCorpId;

	/**
	 * 群发任务选择标签
	 */
	@TableField(updateStrategy = FieldStrategy.IGNORED)
	private String chooseTagStr;

	/**
	 * 标签数量
	 */
	@TableField(exist = false)
	@DbIgnore
	private Integer tagSize;

	/**
	 * 标签组
	 */
	@TableField(updateStrategy = FieldStrategy.IGNORED)
	private String tagGroups;

	/**
	 * 群发内容 文本、附件
	 */
	@TableField(updateStrategy = FieldStrategy.IGNORED)
	private String text;

	@TableField(exist = false)
	@DbIgnore
	private List<Attachments> attachments;

	/**
	 * 附件字符串
	 */
	@TableField(updateStrategy = FieldStrategy.IGNORED)
	private String attachmentsStr;

	/**
	 * 1立即发送，2每日循环，3每周循环,4每月循环
	 */
	@NotNull(message = "定时发送或者立即发送不能为空")
	private Integer sendTimeType;

	private String corn;

	/**
	 * 优惠券id
	 */
	@TableField(updateStrategy = FieldStrategy.IGNORED)
	private String couponIds;

	@DbIgnore
	@TableField(exist = false)
	private String couponName;

	/**
	 * xxljobId
	 */
	private String jobId;

	/**
	 * 定时发送的发送时间
	 */
	@TableField(updateStrategy = FieldStrategy.IGNORED)
	private String sendTime;
	/**
	 * 群发消息任务名称
	 */
	private String name;

	@TableField(exist = false)
	@DbIgnore
	private CornMetaDto cornDto;

	/**
	 * 选择时间
	 */
	private String chooseTime;

	/**
	 * 是否启动(true:启用,false:停用)
	 */
	private Boolean status;

	/**
	 * 1全部、2银河用户、3非银河用户
	 */
	private Integer userScope;

	/** 发送范围 默认2标签用户
	 * 1.全部用户、2标签用户
	 */
	private Integer sendScope;

	/**
	 * 消费范围
	 * 1全部 2消费 3未消费
	 */
	private Integer consumerScope;


	/**
	 * 用户添加客服起始时间
	 */
	@TableField(updateStrategy = FieldStrategy.IGNORED)
	private Date joinStartTime;

	/**
	 * 用户添加客服结束时间
	 */
	@TableField(updateStrategy = FieldStrategy.IGNORED)
	private Date joinEndTime;

	private Boolean deleted;

	/**
	 * 创建时间
	 */
	@TableField(fill = FieldFill.INSERT)
	private Date createdTime;

	/**
	 * 更新时间
	 */
	@TableField(fill = FieldFill.INSERT_UPDATE)
	private Date updateTime;

	@Getter
	public enum Week {
		MON("1"),
		TUE("2"),
		WED("3"),
		THU("4"),
		FRI("5"),
		SAT("6"),
		SUN("7");

		 Week(String week) {
			this.week = week;
		}

		public static String getWeek(String week) {

		 return Arrays.stream(values()).filter(week1 -> week1.getWeek().equals(week)).findFirst().get().name();
		}
		private String week;
	}


}
