package com.persagy.calendar.pojo.dto;

import java.util.Set;

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.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
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 cn.hutool.core.collection.CollectionUtil;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * 这里定义了字典的级别，属于集团、项目、工作历等等，不存在此表中的一律默认为属于工作历级别
 * 且仅定义到 dictType这一级别 
 * 
 * @version
 * @description
 * @company persagy
 * @author zhangqiankun
 * @since 2021年3月3日: 下午7:49:44
 */
@Getter
@Setter
@ToString
@EqualsAndHashCode(callSuper = false)
@TableName("work_calendar_dict")
@IdGenerator(algorithm = IdGeneratorAlgorithm.UUID)
public class WorkCalendarDict extends BaseEntity<WorkCalendarDict> {
	private static final long serialVersionUID = -2320309460723341358L;

	@TableField(updateStrategy = FieldStrategy.NOT_EMPTY)
	private String groupCode; // 集团编码

	@TableField(updateStrategy = FieldStrategy.NOT_EMPTY)
	private String projectId; // 项目ID，集团级别的字典，此值为0

	@TableField(updateStrategy = FieldStrategy.NOT_EMPTY)
	private String calendarId; // 工作历ID，项目级别的字典，此值为0

	@TableField(updateStrategy = FieldStrategy.NOT_EMPTY)
	private String dictType; // 字典类型

	@TableField(updateStrategy = FieldStrategy.NOT_EMPTY)
	private String dictCode; // 字典类型的code

	@TableField(updateStrategy = FieldStrategy.NOT_EMPTY)
	private String dictDesc; // 字典类型描述

	public static Builder builder() {
		return new Builder();
	}

	public static class BuilderQueryWrapper {

		private LambdaQueryWrapper<WorkCalendarDict> queryWrapper = new LambdaQueryWrapper<WorkCalendarDict>();

		public BuilderQueryWrapper idEq(String id) {
			if (StringUtil.isNotBlank(id)) {
				queryWrapper.eq(WorkCalendarDict::getId, id);
			}
			return this;
		}

		public BuilderQueryWrapper groupCodeEq(String groupCode) {
			if (StringUtil.isNotBlank(groupCode)) {
				queryWrapper.eq(WorkCalendarDict::getGroupCode, groupCode);
			}
			return this;
		}

		/**
		 * @param projectId
		 * @param dictTypeLevel 当为null，或者不为0时，才会生效 
		 * @return
		 */
		public BuilderQueryWrapper projectIdEq(String projectId, Integer dictTypeLevel) {
			if (StringUtil.isNotBlank(projectId) && (dictTypeLevel == null || dictTypeLevel != 0)) {
				queryWrapper.eq(WorkCalendarDict::getProjectId, projectId);
			}
			return this;
		}

		/**
		 * @param calendarId
		 * @param dictTypeLevel 当为null，或者不为0时，才会生效 
		 * @return
		 */
		public BuilderQueryWrapper calendarIdEq(String calendarId, Integer dictTypeLevel) {
			if (StringUtil.isNotBlank(calendarId) && (dictTypeLevel == null || dictTypeLevel == 2)) {
				queryWrapper.eq(WorkCalendarDict::getCalendarId, calendarId);
			}
			return this;
		}
		
		public BuilderQueryWrapper dictTypeEq(String dictType) {
			if (StringUtil.isNotBlank(dictType)) {
				queryWrapper.eq(WorkCalendarDict::getDictType, dictType);
			}
			return this;
		}
		
		public BuilderQueryWrapper dictTypeIn(Set<String> dictTypes) {
			if (CollectionUtil.isNotEmpty(dictTypes)) {
				queryWrapper.in(WorkCalendarDict::getDictType, dictTypes);
			}
			return this;
		}

		public BuilderQueryWrapper dictCodeEq(String dictCode) {
			if (StringUtil.isNotBlank(dictCode)) {
				queryWrapper.eq(WorkCalendarDict::getDictCode, dictCode);
			}
			return this;
		}

		public BuilderQueryWrapper dictDescEq(String dictDesc) {
			if (StringUtil.isNotBlank(dictDesc)) {
				queryWrapper.eq(WorkCalendarDict::getDictDesc, dictDesc);
			}
			return this;
		}

		public LambdaQueryWrapper<WorkCalendarDict> builder() {
			return queryWrapper;
		}

	}

	public static class BuilderUpdateWrapper {

		private LambdaUpdateWrapper<WorkCalendarDict> updateWrapper = new LambdaUpdateWrapper<WorkCalendarDict>();

		public BuilderUpdateWrapper idEq(String id) {
			if (StringUtil.isNotBlank(id)) {
				updateWrapper.eq(WorkCalendarDict::getId, id);
			}
			return this;
		}

		public BuilderUpdateWrapper groupCodeEq(String groupCode) {
			if (StringUtil.isNotBlank(groupCode)) {
				updateWrapper.eq(WorkCalendarDict::getGroupCode, groupCode);
			}
			return this;
		}

		/**
		 * @param projectId
		 * @param dictTypeLevel 当为null，或者不为0时，才会生效 
		 * @return
		 */
		public BuilderUpdateWrapper projectIdEq(String projectId, Integer dictTypeLevel) {
			if (StringUtil.isNotBlank(projectId) && (dictTypeLevel == null || dictTypeLevel != 0)) {
				updateWrapper.eq(WorkCalendarDict::getProjectId, projectId);
			}
			return this;
		}

		/**
		 * @param calendarId
		 * @param dictTypeLevel 当为null，或者不为0时，才会生效 
		 * @return
		 */
		public BuilderUpdateWrapper calendarIdEq(String calendarId, Integer dictTypeLevel) {
			if (StringUtil.isNotBlank(calendarId) && (dictTypeLevel == null || dictTypeLevel == 2)) {
				updateWrapper.eq(WorkCalendarDict::getCalendarId, calendarId);
			}
			return this;
		}

		public BuilderUpdateWrapper dictTypeEq(String dictType) {
			if (StringUtil.isNotBlank(dictType)) {
				updateWrapper.eq(WorkCalendarDict::getDictType, dictType);
			}
			return this;
		}

		public BuilderUpdateWrapper dictCodeEq(String dictCode) {
			if (StringUtil.isNotBlank(dictCode)) {
				updateWrapper.eq(WorkCalendarDict::getDictCode, dictCode);
			}
			return this;
		}

		public BuilderUpdateWrapper dictDescEq(String dictDesc) {
			if (StringUtil.isNotBlank(dictDesc)) {
				updateWrapper.eq(WorkCalendarDict::getDictDesc, dictDesc);
			}
			return this;
		}

		public LambdaUpdateWrapper<WorkCalendarDict> builder() {
			return updateWrapper;
		}

	}

	public static class Builder {

		private WorkCalendarDict workCalendarDict = new WorkCalendarDict();

		public Builder id(String id) {
			workCalendarDict.setId(id);
			return this;
		}

		public Builder groupCode(String groupCode) {
			workCalendarDict.setGroupCode(groupCode);
			return this;
		}

		public Builder projectId(String projectId) {
			workCalendarDict.setProjectId(projectId);
			return this;
		}

		public Builder calendarId(String calendarId) {
			workCalendarDict.setCalendarId(calendarId);
			return this;
		}

		public Builder dictType(String dictType) {
			workCalendarDict.setDictType(dictType);
			return this;
		}

		public Builder dictCode(String dictCode) {
			workCalendarDict.setDictCode(dictCode);
			return this;
		}

		public Builder dictDesc(String dictDesc) {
			workCalendarDict.setDictDesc(dictDesc);
			return this;
		}

		public WorkCalendarDict build() {
			return workCalendarDict;
		}
	}

}
