package FieldTypeOperators.server;

import java.util.ArrayList;
import java.util.List;

import com.isomorphic.datasource.BasicDataSource;
import com.isomorphic.datasource.DSRequest;
import com.isomorphic.datasource.DSResponse;
import FieldTypeOperators.shared.FieldTypeOperatorsDTO;

public class FieldTypeOperatorsDataSource extends BasicDataSource {

    private static final long serialVersionUID = -8964705372051184727L;

    private static final String TEXT = "OPERATOR_AS_TEXT";
    private static final String DATE = "OPERATOR_AS_DATE";
    private static final String INTEGER = "OPERATOR_AS_INTEGER";
    private static final String FLOAT = "OPERATOR_AS_FLOAT";
    private static final String BOOLEAN = "OPERATOR_AS_BOOLEAN";

    @Override
    public DSResponse executeFetch(DSRequest request) throws Exception {

        final FieldTypeOperatorsDTO dtoAsTEXT = new FieldTypeOperatorsDTO();
        dtoAsTEXT.setName(TEXT);
        dtoAsTEXT.setTitle(TEXT);
        dtoAsTEXT.setType("text");
        dtoAsTEXT.setLength(FieldTypeOperatorsDTO.DEFAULT_FIELD_LENGTH);

        final FieldTypeOperatorsDTO dtoAsDATE = new FieldTypeOperatorsDTO();
        dtoAsDATE.setName(DATE);
        dtoAsDATE.setTitle(DATE);
        dtoAsDATE.setType("date");
        dtoAsDATE.setLength(FieldTypeOperatorsDTO.DEFAULT_FIELD_LENGTH);

        final FieldTypeOperatorsDTO dtoAsINTEGER = new FieldTypeOperatorsDTO();
        dtoAsINTEGER.setName(INTEGER);
        dtoAsINTEGER.setTitle(INTEGER);
        dtoAsINTEGER.setType("integer");
        dtoAsINTEGER.setLength(FieldTypeOperatorsDTO.DEFAULT_FIELD_LENGTH);

        final FieldTypeOperatorsDTO dtoAsFLOAT = new FieldTypeOperatorsDTO();
        dtoAsFLOAT.setName(FLOAT);
        dtoAsFLOAT.setTitle(FLOAT);
        dtoAsFLOAT.setType("float");
        dtoAsFLOAT.setLength(FieldTypeOperatorsDTO.DEFAULT_FIELD_LENGTH);

        final FieldTypeOperatorsDTO dtoAsBOOLEAN = new FieldTypeOperatorsDTO();
        dtoAsBOOLEAN.setName(BOOLEAN);
        dtoAsBOOLEAN.setTitle(BOOLEAN);
        dtoAsBOOLEAN.setType("boolean");
        dtoAsBOOLEAN.setLength(FieldTypeOperatorsDTO.DEFAULT_FIELD_LENGTH);

        final List<FieldTypeOperatorsDTO> data = new ArrayList<FieldTypeOperatorsDTO>();
        data.add(dtoAsTEXT);
        data.add(dtoAsDATE);
        data.add(dtoAsINTEGER);
        data.add(dtoAsFLOAT);
        data.add(dtoAsBOOLEAN);

        final DSResponse response = new DSResponse();
        response.setData(data);
        response.setSuccess();
        return response;
    }
}
