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

import com.smartgwt.client.data.RestDataSource;
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 PlantsRDS extends RestDataSource {
  private final static PlantsRDS INSTANCE = new PlantsRDS();

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

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

    final DataSourceSequenceField id = new DataSourceSequenceField("id", "ID");
    id.setPrimaryKey(true);
    final DataSourceTextField billingCode = new DataSourceTextField(
        "billing_code", "Fattura Codice", 15);
    billingCode.setForeignKey("CustomersRDS.code");
    setFields(id, new DataSourceTextField("name", "Nome", 40, true),
        new DataSourceTextField("city", "Città", 40, true),
        new DataSourceTextField("address", "Indirizzo", 255),
        new DataSourceTextField("contacts", "Contatti", 255), billingCode,
        new DataSourceTextField("billing_name", "Fattura Nome", 40));

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