package com.facebook.flipper.nativeplugins.table;

import androidx.annotation.Nullable;
import com.facebook.flipper.core.FlipperArray;
import com.facebook.flipper.core.FlipperObject;

public class TableMetadata {

  final Column[] mColumns;
  final QueryableTableRowProvider mResponder;

  FlipperObject serialize() {
    final FlipperObject.Builder columns = new FlipperObject.Builder();
    final FlipperObject.Builder columnSizes = new FlipperObject.Builder();
    final FlipperArray.Builder columnOrder = new FlipperArray.Builder();
    final FlipperArray.Builder filterableColumns = new FlipperArray.Builder();
    for (Column c : mColumns) {
      columns.put(c.id, new FlipperObject.Builder().put("value", c.displayName).build());
      columnSizes.put(c.id, c.displayWidth);
      columnOrder.put(new FlipperObject.Builder().put("key", c.id).put("visible", c.showByDefault));
      if (c.isFilterable) {
        filterableColumns.put(c.id);
      }
    }

    return new FlipperObject.Builder()
        .put("columns", columns.build())
        .put("columnSizes", columnSizes.build())
        .put("columnOrder", columnOrder.build())
        .put("filterableColumns", filterableColumns.build())
        .build();
  }

  private TableMetadata(
      @Nullable Column[] columns, @Nullable QueryableTableRowProvider queryResponder) {
    this.mColumns = columns == null ? new Column[] {} : columns;
    this.mResponder = queryResponder;
  }

  public static class Builder {
    private Column[] columns;
    private QueryableTableRowProvider queryResponder;

    public Builder columns(Column... columns) {
      this.columns = columns;
      return this;
    }

    public Builder queryResponder(QueryableTableRowProvider responder) {
      this.queryResponder = responder;
      return this;
    }

    public TableMetadata build() {
      return new TableMetadata(columns, queryResponder);
    }
  }
}

@@ -175,16 +175,85 @@
 rObject;
+%0Aimport com.facebook.flipper.nativeplugins.components.ToolbarSection;
 %0A%0Apublic
@@ -344,24 +344,99 @@
  mResponder;
+%0A  final ToolbarSection mTopToolbar;%0A  final ToolbarSection mBottomToolbar;
 %0A%0A  FlipperO
@@ -1332,32 +1332,203 @@
 olumns.build())%0A
+        .put(%22topToolbar%22, mTopToolbar != null ? mTopToolbar.serialize() : null)%0A        .put(%22bottomToolbar%22, mBottomToolbar != null ? mBottomToolbar.serialize() : null)%0A
         .build()
@@ -1592,16 +1592,22 @@
 columns,
+%0A     
  @Nullab
@@ -1641,32 +1641,121 @@
 r queryResponder
+,%0A      @Nullable ToolbarSection topToolbar,%0A      @Nullable ToolbarSection bottomToolbar
 ) %7B%0A    this.mCo
@@ -1845,16 +1845,92 @@
 ponder;%0A
+    this.mTopToolbar = topToolbar;%0A    this.mBottomToolbar = bottomToolbar;%0A
   %7D%0A%0A  p
@@ -2041,16 +2041,97 @@
 sponder;
+%0A    private ToolbarSection topToolbar;%0A    private ToolbarSection bottomToolbar;
 %0A%0A    pu
@@ -2358,32 +2358,252 @@
 rn this;%0A    %7D%0A%0A
+    public Builder topToolbar(ToolbarSection bar) %7B%0A      this.topToolbar = bar;%0A      return this;%0A    %7D%0A%0A    public Builder bottomToolbar(ToolbarSection bar) %7B%0A      this.bottomToolbar = bar;%0A      return this;%0A    %7D%0A%0A
     public Table
@@ -2675,16 +2675,43 @@
 esponder
+, topToolbar, bottomToolbar
 );%0A    %7D

Add top and bottom toolbars to native plugins