package info.archinnov.achilles.generated;

import com.datastax.driver.core.ClusteringOrder;
import com.datastax.driver.core.ConsistencyLevel;
import com.datastax.driver.core.DataType;
import com.datastax.driver.core.Row;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.common.reflect.TypeToken;
import info.archinnov.achilles.generated.function.Date_Type;
import info.archinnov.achilles.generated.function.Double_Type;
import info.archinnov.achilles.generated.function.Long_Type;
import info.archinnov.achilles.generated.function.PartitionKeys_Type;
import info.archinnov.achilles.generated.meta.entity.TestEntityWithCustomConstructorAndDeclaredFields_AchillesMeta.ColumnsForFunctions;
import info.archinnov.achilles.internals.apt.annotations.AchillesMeta;
import info.archinnov.achilles.internals.codec.FallThroughCodec;
import info.archinnov.achilles.internals.metamodel.AbstractEntityProperty;
import info.archinnov.achilles.internals.metamodel.AbstractProperty;
import info.archinnov.achilles.internals.metamodel.SimpleProperty;
import info.archinnov.achilles.internals.metamodel.columns.ClusteringColumnInfo;
import info.archinnov.achilles.internals.metamodel.columns.ColumnInfo;
import info.archinnov.achilles.internals.metamodel.columns.ColumnType;
import info.archinnov.achilles.internals.metamodel.columns.FieldInfo;
import info.archinnov.achilles.internals.metamodel.columns.PartitionKeyInfo;
import info.archinnov.achilles.internals.metamodel.index.IndexInfo;
import info.archinnov.achilles.internals.sample_classes.parser.entity.TestEntityWithCustomConstructorAndDeclaredFields;
import info.archinnov.achilles.internals.strategy.naming.InternalNamingStrategy;
import info.archinnov.achilles.type.strategy.InsertStrategy;
import java.lang.Class;
import java.lang.Double;
import java.lang.Integer;
import java.lang.Long;
import java.lang.Override;
import java.lang.String;
import java.lang.SuppressWarnings;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Optional;

/**
 * Meta class of all entities of type TestEntityWithCustomConstructorAndDeclaredFields<br/>
 * The meta class is responsible for<br/>
 * <ul>
 *    <li>determining runtime consistency levels (read/write,serial)<li/>
 *    <li>determining runtime insert strategy<li/>
 *    <li>trigger event interceptors (if any)<li/>
 *    <li>map a Row back to an instance of TestEntityWithCustomConstructorAndDeclaredFields<li/>
 *    <li>determine runtime keyspace name using static annotations and runtime SchemaNameProvider (if any)<li/>
 *    <li>determine runtime table name using static annotations and runtime SchemaNameProvider (if any)<li/>
 *    <li>generate schema during bootstrap<li/>
 *    <li>validate schema during bootstrap<li/>
 *    <li>expose all property meta classes for encoding/decoding purpose on unitary columns<li/>
 * <ul/>
 */
@AchillesMeta
public final class TestEntityWithCustomConstructorAndDeclaredFields_AchillesMeta extends AbstractEntityProperty<TestEntityWithCustomConstructorAndDeclaredFields> {
  /**
   * Meta class for 'id' property <br/>
   * The meta class exposes some useful methods: <ul>
   *    <li>encodeFromJava: encode a property from raw Java to CQL java compatible type </li>
   *    <li>encodeField: extract the current property value from the given TestEntityWithCustomConstructorAndDeclaredFields instance and encode to CQL java compatible type </li>
   *    <li>decodeFromGettable: decode from a {@link com.datastax.driver.core.GettableData} instance (Row, UDTValue, TupleValue) the current property</li>
   * </ul>
   */
  @SuppressWarnings({"serial", "unchecked"})
  public static final SimpleProperty<TestEntityWithCustomConstructorAndDeclaredFields, Long, Long> id = new SimpleProperty<TestEntityWithCustomConstructorAndDeclaredFields, Long, Long>(new FieldInfo<>((TestEntityWithCustomConstructorAndDeclaredFields entity$) -> entity$.getId(), (TestEntityWithCustomConstructorAndDeclaredFields entity$, Long value$) -> {}, "id", "id", ColumnType.PARTITION, new PartitionKeyInfo(1, false), IndexInfo.noIndex()), DataType.bigint(), gettableData$ -> gettableData$.get("id", long.class), (settableData$, value$) -> settableData$.set("id", value$, long.class), new TypeToken<Long>(){}, new TypeToken<Long>(){}, new FallThroughCodec<>(Long.class));

  /**
   * Meta class for 'date' property <br/>
   * The meta class exposes some useful methods: <ul>
   *    <li>encodeFromJava: encode a property from raw Java to CQL java compatible type </li>
   *    <li>encodeField: extract the current property value from the given TestEntityWithCustomConstructorAndDeclaredFields instance and encode to CQL java compatible type </li>
   *    <li>decodeFromGettable: decode from a {@link com.datastax.driver.core.GettableData} instance (Row, UDTValue, TupleValue) the current property</li>
   * </ul>
   */
  @SuppressWarnings({"serial", "unchecked"})
  public static final SimpleProperty<TestEntityWithCustomConstructorAndDeclaredFields, Date, Date> date = new SimpleProperty<TestEntityWithCustomConstructorAndDeclaredFields, Date, Date>(new FieldInfo<>((TestEntityWithCustomConstructorAndDeclaredFields entity$) -> entity$.getDate(), (TestEntityWithCustomConstructorAndDeclaredFields entity$, Date value$) -> {}, "date", "date", ColumnType.CLUSTERING, new ClusteringColumnInfo(1, false, ClusteringOrder.ASC), IndexInfo.noIndex()), DataType.timestamp(), gettableData$ -> gettableData$.get("date", java.util.Date.class), (settableData$, value$) -> settableData$.set("date", value$, java.util.Date.class), new TypeToken<Date>(){}, new TypeToken<Date>(){}, new FallThroughCodec<>(Date.class));

  /**
   * Meta class for 'value' property <br/>
   * The meta class exposes some useful methods: <ul>
   *    <li>encodeFromJava: encode a property from raw Java to CQL java compatible type </li>
   *    <li>encodeField: extract the current property value from the given TestEntityWithCustomConstructorAndDeclaredFields instance and encode to CQL java compatible type </li>
   *    <li>decodeFromGettable: decode from a {@link com.datastax.driver.core.GettableData} instance (Row, UDTValue, TupleValue) the current property</li>
   * </ul>
   */
  @SuppressWarnings({"serial", "unchecked"})
  public static final SimpleProperty<TestEntityWithCustomConstructorAndDeclaredFields, Double, Double> value = new SimpleProperty<TestEntityWithCustomConstructorAndDeclaredFields, Double, Double>(new FieldInfo<>((TestEntityWithCustomConstructorAndDeclaredFields entity$) -> entity$.getValue(), (TestEntityWithCustomConstructorAndDeclaredFields entity$, Double value$) -> {}, "value", "value", ColumnType.NORMAL, new ColumnInfo(false), IndexInfo.noIndex()), DataType.cdouble(), gettableData$ -> gettableData$.get("value", java.lang.Double.class), (settableData$, value$) -> settableData$.set("value", value$, java.lang.Double.class), new TypeToken<Double>(){}, new TypeToken<Double>(){}, new FallThroughCodec<>(Double.class));

  /**
   * Static class to expose "TestEntityWithCustomConstructorAndDeclaredFields_AchillesMeta" fields for <strong>type-safe</strong> function calls */
  public static final TestEntityWithCustomConstructorAndDeclaredFields_AchillesMeta.ColumnsForFunctions COLUMNS = new TestEntityWithCustomConstructorAndDeclaredFields_AchillesMeta.ColumnsForFunctions();
  ;

  @Override
  protected Class<TestEntityWithCustomConstructorAndDeclaredFields> getEntityClass() {
    return TestEntityWithCustomConstructorAndDeclaredFields.class;
  }

  @Override
  protected String getDerivedTableOrViewName() {
    return "testentitywithcustomconstructoranddeclaredfields";
  }

  @Override
  protected BiMap<String, String> fieldNameToCqlColumn() {
    BiMap<String,String> map = HashBiMap.create(3);
    map.put("id", "id");
    map.put("date", "date");
    map.put("value", "value");
    return map;
  }

  @Override
  protected Optional<ConsistencyLevel> getStaticReadConsistency() {
    return Optional.empty();
  }

  @Override
  protected Optional<InternalNamingStrategy> getStaticNamingStrategy() {
    return Optional.empty();
  }

  @Override
  protected List<AbstractProperty<TestEntityWithCustomConstructorAndDeclaredFields, ?, ?>> getPartitionKeys() {
    return Arrays.asList(id);
  }

  @Override
  protected List<AbstractProperty<TestEntityWithCustomConstructorAndDeclaredFields, ?, ?>> getClusteringColumns() {
    return Arrays.asList(date);
  }

  @Override
  protected List<AbstractProperty<TestEntityWithCustomConstructorAndDeclaredFields, ?, ?>> getNormalColumns() {
    return Arrays.asList(value);
  }

  @Override
  protected List<AbstractProperty<TestEntityWithCustomConstructorAndDeclaredFields, ?, ?>> getComputedColumns() {
    return Arrays.asList();
  }

  @Override
  protected List<AbstractProperty<TestEntityWithCustomConstructorAndDeclaredFields, ?, ?>> getConstructorInjectedColumns() {
    return Arrays.asList(id,date,value);
  }

  @Override
  protected boolean isCounterTable() {
    return false;
  }

  @Override
  protected Optional<String> getStaticKeyspace() {
    return Optional.empty();
  }

  @Override
  protected Optional<String> getStaticTableOrViewName() {
    return Optional.empty();
  }

  @Override
  protected Optional<ConsistencyLevel> getStaticWriteConsistency() {
    return Optional.empty();
  }

  @Override
  protected Optional<ConsistencyLevel> getStaticSerialConsistency() {
    return Optional.empty();
  }

  @Override
  protected Optional<Integer> getStaticTTL() {
    return Optional.empty();
  }

  @Override
  protected Optional<InsertStrategy> getStaticInsertStrategy() {
    return Optional.empty();
  }

  @Override
  protected List<AbstractProperty<TestEntityWithCustomConstructorAndDeclaredFields, ?, ?>> getStaticColumns() {
    return Arrays.asList();
  }

  @Override
  protected List<AbstractProperty<TestEntityWithCustomConstructorAndDeclaredFields, ?, ?>> getCounterColumns() {
    return Arrays.asList();
  }

  @Override
  protected TestEntityWithCustomConstructorAndDeclaredFields newInstanceFromCustomConstructor(final Row row, final List<String> cqlColumns) {
    final Long id_value = cqlColumns.contains(id.getColumnForSelect()) ? id.decodeFromGettable(row): null;
    final Date date_value = cqlColumns.contains(date.getColumnForSelect()) ? date.decodeFromGettable(row): null;
    final Double value_value = cqlColumns.contains(value.getColumnForSelect()) ? value.decodeFromGettable(row): null;
    return new TestEntityWithCustomConstructorAndDeclaredFields(id_value,date_value,value_value);
  }

  /**
   * Utility class to expose all fields with their CQL type for function call */
  public static final class ColumnsForFunctions {
    /**
     * <br/>
     * Field to be used for <em>manager.dsl().select().function(...)</em> call
     * <br/>
     * This is an alias for the field <strong>"id"</strong> */
    public final Long_Type ID = new Long_Type(Optional.empty()){
      @Override
      protected String cqlColumn() {
          return "id";
    }
      @Override
      public boolean isFunctionCall() {
          return false;
    }
      }
    ;

    /**
     * <br/>
     * Field to be used for <em>manager.dsl().select().function(...)</em> call
     * <br/>
     * This is an alias for the field <strong>"date"</strong> */
    public final Date_Type DATE = new Date_Type(Optional.empty()){
      @Override
      protected String cqlColumn() {
          return "date";
    }
      @Override
      public boolean isFunctionCall() {
          return false;
    }
      }
    ;

    /**
     * <br/>
     * Field to be used for <em>manager.dsl().select().function(...)</em> call
     * <br/>
     * This is an alias for the field <strong>"value"</strong> */
    public final Double_Type VALUE = new Double_Type(Optional.empty()){
      @Override
      protected String cqlColumn() {
          return "value";
    }
      @Override
      public boolean isFunctionCall() {
          return false;
    }
      }
    ;

    /**
     * <br/>
     * Field to be used with <em>SystemFunctions.token(xxx_AchillesMeta.COLUMNS.PARTITION_KEYS, "tokens")</em> call
     * <br/>
     */
    public final PartitionKeys_Type PARTITION_KEYS = new PartitionKeys_Type(new ArrayList<String>() {
     {
     add("id"); }
      })
    ;
  }
}