class ActionRequestUtil {

    public static ActionRequestKey getIndexRequestFromCamusHeader(IndexedRecord header, Schema headerSchema) {
        ActionRequestKey.Builder builder = ActionRequestKey.newBuilder();
        builder.setAction(Action.INDEX);
        if (header != null && headerSchema != null) {
            Schema.Field tsField = headerSchema.getField("time");
            Schema.Field idField = headerSchema.getField("id");
            if (tsField == null) {
                //For backward compatibility
                tsField = headerSchema.getField("timestamp");
            }
            if (tsField != null) {
                Object ts = header.get(tsField.pos());
                if (ts instanceof Long) {
                    builder.setEventTsUnixMs((Long) ts);
                    builder.setPartitionTsUnixMs((Long) ts);
                }
            }
            if (idField != null) {
                Object id = header.get(idField.pos());
                if (id instanceof CharSequence) {
                    builder.setId((CharSequence) id);
                }
            }
        }
        return builder.build();
    }

}