package org.example.domain.finder;

import com.avaje.ebean.Finder;
import com.avaje.ebean.OrderBy;
import com.avaje.ebean.PagedList;
import com.avaje.ebean.Query;
import org.example.domain.Order;
import org.example.domain.query.QOrder;

import java.sql.Date;
import java.util.List;

public class OrderFinder extends Finder<Long,Order> {

  /**
   * Construct using the default EbeanServer.
   */
  public OrderFinder() {
    super(Order.class);
  }

  /**
   * Construct with a given EbeanServer.
   */
  public OrderFinder(String serverName) {
    super(Order.class, serverName);
  }

  /**
   * Start a new typed query.
   */
  protected QOrder where() {
     return new QOrder(db());
  }


  /**
   * Find orders with the given status.
   */
  public List<Order> byStatus(Order.Status... values) {

    return where()
        .status.in(values)
        .orderBy()
          .orderDate.desc()
          .id.desc()
        .findList();
  }

//  public Query<Order> queryByStatus(Order.Status... values) {
//
//    return where()
//        .status.in(values)
//        .orderBy()
//          .orderDate.desc()
//          .id.desc()
//        .query();
//  }

  /**
   * Find new orders with an orderDate after the given since value.
   */
  public PagedList<Order> newOrdersSince(Date since, int pageIndex) {

    return where()
        .status.in()
        .status.eq(Order.Status.NEW)
        .or()
          .orderDate.after(since)
          .orderDate.isNull()
        .endOr()
        .findPagedList(pageIndex, 100);
  }
}

@@ -685,17 +685,16 @@
 );%0A  %7D%0A%0A
-%0A
   /**%0A  
@@ -938,226 +938,8 @@
  %7D%0A%0A
-//  public Query%3COrder%3E queryByStatus(Order.Status... values) %7B%0A//%0A//    return where()%0A//        .status.in(values)%0A//        .orderBy()%0A//          .orderDate.desc()%0A//          .id.desc()%0A//        .query();%0A//  %7D%0A%0A
   /*

Tidy - no effective change