package com.persagy.calendar.pojo.dto;

import java.util.List;
import java.util.Set;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.persagy.calendar.constant.WorkCalendarConstant;
import com.persagy.common.annotation.IdGenerator;
import com.persagy.common.enums.IdGeneratorAlgorithm;
import com.persagy.common.utils.StringUtil;
import com.persagy.db.model.BaseEntity;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * 工作历主表
 * 
 * @version 1.0.0
 * @company persagy
 * @author zhangqiankun
 * @date 2020-10-02 11:33:00
 */
@Getter
@Setter
@ToString
@TableName("work_calendar")
@EqualsAndHashCode(callSuper = false)
@IdGenerator(prefix = WorkCalendarConstant.WORK_CALENDAR_ID_PREFIX, algorithm = IdGeneratorAlgorithm.SNOW_STR)
public class WorkCalendar extends BaseEntity<WorkCalendar> {
	private static final long serialVersionUID = -1507838782036817943L;

	@TableField(updateStrategy = FieldStrategy.NOT_EMPTY)
	private String groupCode; // 集团编码
	
	@TableField(updateStrategy = FieldStrategy.NOT_EMPTY)
	private String projectId; // 工作历分类ID

	@TableField(updateStrategy = FieldStrategy.NOT_EMPTY)
	private String calendarName; // 同一PROJECT_ID下唯一，代码判断

	@TableField(updateStrategy = FieldStrategy.NOT_EMPTY)
	private String calendarDesc; // 工作历描述

	@TableField(fill = FieldFill.INSERT, updateStrategy = FieldStrategy.NOT_EMPTY)
	private String createTime; // 创建时间

	@TableField(fill = FieldFill.INSERT_UPDATE, updateStrategy = FieldStrategy.NOT_EMPTY)
	private String updateTime; // 更新时间

	@TableField(updateStrategy = FieldStrategy.NOT_EMPTY)
	private String updateUser; // 操作用户ID

	@TableField(updateStrategy = FieldStrategy.NOT_EMPTY)
	private String delFlag; // 0-正常；1-删除

	// objectId, objectName
	@TableField(exist = false)
	private List<JSONObject> objects;
	
	@TableField(exist = false)
	private Set<String> objIds;	//对象ID集合，空间、建筑、楼层、项目
	
	public static class Builder {

		private QueryWrapper<WorkCalendar> queryWrapper = null;

		private UpdateWrapper<WorkCalendar> updateWrapper = null;

		public Builder createQueryWrapper() {
			queryWrapper = new QueryWrapper<WorkCalendar>();
			return this;
		}

		public Builder createUpdateWrapper() {
			updateWrapper = new UpdateWrapper<WorkCalendar>();
			return this;
		}

		public Builder idEq(String id) {
			if (StringUtil.isNotBlank(id)) {
				if (updateWrapper != null) {
					updateWrapper.eq("ID", id);
				} else {
					queryWrapper.eq("ID", id);
				}
			}
			return this;
		}

		public Builder groupCodeEq(String groupCode) {
			if (StringUtil.isNotBlank(groupCode)) {
				if (updateWrapper != null) {
					updateWrapper.eq("GROUP_CODE", groupCode);
				} else {
					queryWrapper.eq("GROUP_CODE", groupCode);
				}
			}
			return this;
		}
		
		public Builder projectIdEq(String projectId) {
			if (StringUtil.isNotBlank(projectId)) {
				if (updateWrapper != null) {
					updateWrapper.eq("PROJECT_ID", projectId);
				} else {
					queryWrapper.eq("PROJECT_ID", projectId);
				}
			}
			return this;
		}

		public Builder calendarNameEq(String calendarName) {
			if (StringUtil.isNotBlank(calendarName)) {
				if (updateWrapper != null) {
					updateWrapper.eq("CALENDAR_NAME", calendarName);
				} else {
					queryWrapper.eq("CALENDAR_NAME", calendarName);
				}
			}
			return this;
		}
		
		public Builder calendarNameLike(String calendarName) {
			if (StringUtil.isNotBlank(calendarName)) {
				if (updateWrapper != null) {
					updateWrapper.like("CALENDAR_NAME", calendarName);
				} else {
					queryWrapper.like("CALENDAR_NAME", calendarName);
				}
			}
			return this;
		}

		public Builder calendarDescEq(String calendarDesc) {
			if (StringUtil.isNotBlank(calendarDesc)) {
				if (updateWrapper != null) {
					updateWrapper.eq("CALENDAR_DESC", calendarDesc);
				} else {
					queryWrapper.eq("CALENDAR_DESC", calendarDesc);
				}
			}
			return this;
		}

		public Builder createTimeEq(String createTime) {
			if (StringUtil.isNotBlank(createTime)) {
				if (updateWrapper != null) {
					updateWrapper.eq("CREATE_TIME", createTime);
				} else {
					queryWrapper.eq("CREATE_TIME", createTime);
				}
			}
			return this;
		}

		public Builder updateTimeEq(String updateTime) {
			if (StringUtil.isNotBlank(updateTime)) {
				if (updateWrapper != null) {
					updateWrapper.eq("UPDATE_TIME", updateTime);
				} else {
					queryWrapper.eq("UPDATE_TIME", updateTime);
				}
			}
			return this;
		}

		public Builder updateUserEq(String updateUser) {
			if (StringUtil.isNotBlank(updateUser)) {
				if (updateWrapper != null) {
					updateWrapper.eq("UPDATE_USER", updateUser);
				} else {
					queryWrapper.eq("UPDATE_USER", updateUser);
				}
			}
			return this;
		}

		public Builder delFlagEq(String delFlag) {
			if (StringUtil.isNotBlank(delFlag)) {
				if (updateWrapper != null) {
					updateWrapper.eq("DEL_FLAG", delFlag);
				} else {
					queryWrapper.eq("DEL_FLAG", delFlag);
				}
			}
			return this;
		}

		public QueryWrapper<WorkCalendar> builderQueryWrapper() {
			return queryWrapper;
		}

		public UpdateWrapper<WorkCalendar> builderUpdateWrapper() {
			return updateWrapper;
		}
	}
}
