package com.bonus.canteen.core.common.export.po;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.write.handler.WriteHandler;
import com.bonus.canteen.core.common.export.constant.ExportTaskWaitPolicy;

import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List;
import java.util.function.Function;
import java.util.function.LongFunction;

public class ExcelExportParam<T> {
   private String fileName;
   private Long totalCount;
   private LongFunction<Collection<T>> dataQueryFunc;
   private Function<T, String> sheetNameFunc;
   private LocalDateTime expiredTime;
   private boolean ifPrivate = true;
   private ExportTaskWaitPolicy waitPolicy;
   private String sheetName;
   private Class<T> headerClass;
   private List<String> columnNames;
   private List<Converter<?>> additionalConvertors;
   private List<WriteHandler> additionalWriteHandlers;

   public static <T> ExcelExportParam<T> ofHeadClass(Class<T> headerClass) {
      return (new ExcelExportParam()).setHeaderClass(headerClass);
   }

   public ExcelExportParam() {
      this.waitPolicy = ExportTaskWaitPolicy.JOIN;
   }

   public String getFileName() {
      return this.fileName;
   }

   public Long getTotalCount() {
      return this.totalCount;
   }

   public LongFunction<Collection<T>> getDataQueryFunc() {
      return this.dataQueryFunc;
   }

   public Function<T, String> getSheetNameFunc() {
      return this.sheetNameFunc;
   }

   public LocalDateTime getExpiredTime() {
      return this.expiredTime;
   }

   public boolean isIfPrivate() {
      return this.ifPrivate;
   }

   public ExportTaskWaitPolicy getWaitPolicy() {
      return this.waitPolicy;
   }

   public String getSheetName() {
      return this.sheetName;
   }

   public Class<T> getHeaderClass() {
      return this.headerClass;
   }

   public List<String> getColumnNames() {
      return this.columnNames;
   }

   public List<Converter<?>> getAdditionalConvertors() {
      return this.additionalConvertors;
   }

   public List<WriteHandler> getAdditionalWriteHandlers() {
      return this.additionalWriteHandlers;
   }

   public ExcelExportParam<T> setFileName(final String fileName) {
      this.fileName = fileName;
      return this;
   }

   public ExcelExportParam<T> setTotalCount(final Long totalCount) {
      this.totalCount = totalCount;
      return this;
   }

   public ExcelExportParam<T> setDataQueryFunc(final LongFunction<Collection<T>> dataQueryFunc) {
      this.dataQueryFunc = dataQueryFunc;
      return this;
   }

   public ExcelExportParam<T> setSheetNameFunc(final Function<T, String> sheetNameFunc) {
      this.sheetNameFunc = sheetNameFunc;
      return this;
   }

   public ExcelExportParam<T> setExpiredTime(final LocalDateTime expiredTime) {
      this.expiredTime = expiredTime;
      return this;
   }

   public ExcelExportParam<T> setIfPrivate(final boolean ifPrivate) {
      this.ifPrivate = ifPrivate;
      return this;
   }

   public ExcelExportParam<T> setWaitPolicy(final ExportTaskWaitPolicy waitPolicy) {
      this.waitPolicy = waitPolicy;
      return this;
   }

   public ExcelExportParam<T> setSheetName(final String sheetName) {
      this.sheetName = sheetName;
      return this;
   }

   public ExcelExportParam<T> setHeaderClass(final Class<T> headerClass) {
      this.headerClass = headerClass;
      return this;
   }

   public ExcelExportParam<T> setColumnNames(final List<String> columnNames) {
      this.columnNames = columnNames;
      return this;
   }

   public ExcelExportParam<T> setAdditionalConvertors(final List<Converter<?>> additionalConvertors) {
      this.additionalConvertors = additionalConvertors;
      return this;
   }

   public ExcelExportParam<T> setAdditionalWriteHandlers(final List<WriteHandler> additionalWriteHandlers) {
      this.additionalWriteHandlers = additionalWriteHandlers;
      return this;
   }
}
