package it.microlog.apps.esempio.client.data;

import com.smartgwt.client.data.RestDataSource;
import com.smartgwt.client.data.fields.DataSourceIntegerField;
import com.smartgwt.client.data.fields.DataSourceSequenceField;
import com.smartgwt.client.data.fields.DataSourceTextField;
import com.smartgwt.client.types.DSDataFormat;
import com.smartgwt.client.types.RPCTransport;

public final class PlantComponentsRDS extends RestDataSource {
  private final static PlantComponentsRDS INSTANCE = new PlantComponentsRDS();

  public final static PlantComponentsRDS getInstance() {
    return INSTANCE;
  }

  private PlantComponentsRDS() {
    setID("PlantPartsRDS");
    setDataFormat(DSDataFormat.JSON);
    setDataTransport(RPCTransport.XMLHTTPREQUEST);

    final DataSourceSequenceField id = new DataSourceSequenceField("id", "ID");
    id.setPrimaryKey(true);
    final DataSourceSequenceField plant_id = new DataSourceSequenceField(
        "plant_id", "ID Impianto", 11, true);
    plant_id.setForeignKey("PlantsRDS.id");
    final DataSourceTextField article_code = new DataSourceTextField(
        "article_code", "Codice Articolo", 10, true);
    article_code.setForeignKey("ArticlesRDS.code");
    setFields(id, plant_id, article_code, new DataSourceIntegerField(
        "quantity", "Quantità", 10, true), new DataSourceTextField("notes",
        "Note", 255));

    setDataURL("/plant_components.json");
  }
}
