package mil.nga.geopackage.features;

import java.util.Map;
import java.util.Map.Entry;

import mil.nga.geopackage.GeoPackage;
import mil.nga.geopackage.features.user.FeatureColumn;
import mil.nga.geopackage.features.user.FeatureDao;
import mil.nga.geopackage.features.user.FeatureRow;
import mil.nga.sf.Geometry;

/**
 * OGC API Feature Generator
 * 
 * @author osbornb
 */
public class OAPIFeatureGenerator extends OAPIFeatureCoreGenerator {

	/**
	 * Feature DAO
	 */
	protected FeatureDao featureDao;

	/**
	 * Constructor
	 *
	 * @param geoPackage
	 *            GeoPackage
	 * @param tableName
	 *            table name
	 * @param server
	 *            server url
	 * @param name
	 *            collection identifier
	 */
	public OAPIFeatureGenerator(GeoPackage geoPackage, String tableName,
			String server, String name) {
		super(geoPackage, tableName, server, name);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public GeoPackage getGeoPackage() {
		return (GeoPackage) geoPackage;
	}

	/**
	 * Get the feature DAO
	 * 
	 * @return feature DAO
	 */
	public FeatureDao getFeatureDao() {
		return featureDao;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected void addColumn(FeatureColumn featureColumn) {
		featureDao.addColumn(featureColumn);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected void initializeTable() {
		featureDao = getGeoPackage().getFeatureDao(geometryColumns);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected void saveFeature(Geometry geometry, Map<String, Object> values) {

		FeatureRow featureRow = featureDao.newRow();

		featureRow.setGeometry(createGeometryData(geometry));
		for (Entry<String, Object> value : values.entrySet()) {
			featureRow.setValue(value.getKey(), value.getValue());
		}

		saveFeature(featureRow);
	}

	/**
	 * Save the feature row
	 *
	 * @param featureRow
	 *            feature row
	 */
	protected void saveFeature(FeatureRow featureRow) {
		featureDao.create(featureRow);
	}

}

@@ -674,20 +674,18 @@
  @param 
-name
+id
 %0A%09 *    
@@ -814,20 +814,18 @@
  String 
-name
+id
 ) %7B%0A%09%09su
@@ -859,20 +859,18 @@
 server, 
-name
+id
 );%0A%09%7D%0A%0A%09

rename collection name to id