/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.apache.myfaces.tobago.example.test;

import org.apache.myfaces.tobago.example.demo.LocaleEntry;
import org.apache.myfaces.tobago.example.demo.LocaleList;
import org.apache.myfaces.tobago.example.demo.SolarObject;
import org.apache.myfaces.tobago.example.demo.AstroData;

import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import javax.faces.model.DataModel;
import javax.inject.Inject;
import javax.inject.Named;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@SessionScoped
@Named
public class SheetTestController implements Serializable {

  @Inject
  private AstroData astroData;

  private List<SolarObject> solarArray;
  private List<SolarObject> solarArray3;
  private DataModel undefined;
  private List<LocaleEntry> localeList;

  @PostConstruct
  private void init() {
    solarArray = astroData.findAll().collect(Collectors.toList());
    solarArray3 = astroData.findAll().limit(3).collect(Collectors.toList());
    undefined = new UndefinedRowCountDataModel(solarArray);
    // Create a copy for sorting, because the LocaleList.DATA is not modifiable.
    localeList = new ArrayList<>(LocaleList.DATA);
  }

  public List<SolarObject> getSolarArray() {
    return solarArray;
  }

  public List<SolarObject> getSolarArray3() {
    return solarArray3;
  }

  public List<LocaleEntry> getLocaleList() {
    return localeList;
  }

  public DataModel getUndefined() {
    return undefined;
  }
}
