package ru.micord.ervu_dashboard.component.combobox;

import java.time.LocalDate;

import rpc.LoadGraphSource;

import ru.cg.webbpm.modules.database.bean.annotation.GraphSource;
import ru.cg.webbpm.modules.database.bean.entity_graph.EntityColumn;
import ru.cg.webbpm.modules.database.bean.filter.EntityFilter;
import ru.cg.webbpm.modules.database.bean.filter.FilterOperation;
import ru.cg.webbpm.modules.standard_annotations.editor.Visible;
import ru.cg.webbpm.modules.standard_annotations.validation.NotNull;

/**
 * @author r.latypov
 */
public class CurrentYearFirstDayFilterService implements FilterService {
  @NotNull(predicate = "table == null && column == null")
  @Visible(predicate = "table == null && column == null")
  @GraphSource(
      value = LoadGraphSource.class, scanMode = GraphSource.ScanMode.SELF, singleSource = false)
  public EntityColumn entityColumn;
  @NotNull(predicate = "entityColumn == null")
  @Visible(predicate = "entityColumn == null")
  public String table;
  @NotNull(predicate = "entityColumn == null")
  @Visible(predicate = "entityColumn == null")
  public String column;

  @NotNull
  public FilterOperation filterOperation;

  @Override
  public EntityFilter getEntityFilter() {
    return new EntityFilter(
        LocalDate.now().withDayOfYear(1),
        filterOperation, entityColumn == null ? new EntityColumn(table, column) : entityColumn
    );
  }
}
