/* Generated by `sidemantic dashboard types`. Do not edit by hand. */
export const sidemanticSchema = {
  "schema": "sidemantic.schema.v1",
  "models": {
    "orders": {
      "metrics": {
        "gross_margin": {
          "field": "orders.gross_margin",
          "type": "number",
          "agg": "sum",
          "description": "Total gross margin."
        },
        "order_count": {
          "field": "orders.order_count",
          "type": "number",
          "agg": "count",
          "description": "Number of orders."
        },
        "revenue": {
          "field": "orders.revenue",
          "type": "number",
          "agg": "sum",
          "description": "Total order revenue."
        }
      },
      "dimensions": {
        "channel": {
          "field": "orders.channel",
          "fields": [
            "orders.channel"
          ],
          "type": "categorical",
          "description": "Acquisition or sales channel.",
          "label": null
        },
        "created_at": {
          "field": "orders.created_at",
          "fields": [
            "orders.created_at",
            "orders.created_at__second",
            "orders.created_at__minute",
            "orders.created_at__hour",
            "orders.created_at__day",
            "orders.created_at__week",
            "orders.created_at__month",
            "orders.created_at__quarter",
            "orders.created_at__year"
          ],
          "type": "time",
          "description": "Date the order was created.",
          "label": null
        },
        "customer_tier": {
          "field": "orders.customer_tier",
          "fields": [
            "orders.customer_tier"
          ],
          "type": "categorical",
          "description": "Customer segment.",
          "label": null
        },
        "product_line": {
          "field": "orders.product_line",
          "fields": [
            "orders.product_line"
          ],
          "type": "categorical",
          "description": "Product family.",
          "label": null
        },
        "region": {
          "field": "orders.region",
          "fields": [
            "orders.region"
          ],
          "type": "categorical",
          "description": "Sales region.",
          "label": null
        }
      }
    }
  },
  "metrics": [
    "orders.gross_margin",
    "orders.order_count",
    "orders.revenue"
  ],
  "dimensions": [
    "orders.channel",
    "orders.created_at",
    "orders.created_at__day",
    "orders.created_at__hour",
    "orders.created_at__minute",
    "orders.created_at__month",
    "orders.created_at__quarter",
    "orders.created_at__second",
    "orders.created_at__week",
    "orders.created_at__year",
    "orders.customer_tier",
    "orders.product_line",
    "orders.region"
  ],
  "fields": [
    "orders.channel",
    "orders.created_at",
    "orders.created_at__day",
    "orders.created_at__hour",
    "orders.created_at__minute",
    "orders.created_at__month",
    "orders.created_at__quarter",
    "orders.created_at__second",
    "orders.created_at__week",
    "orders.created_at__year",
    "orders.customer_tier",
    "orders.gross_margin",
    "orders.order_count",
    "orders.product_line",
    "orders.region",
    "orders.revenue"
  ],
  "fieldTypes": {
    "orders.channel": "string",
    "orders.created_at": "date",
    "orders.created_at__day": "date",
    "orders.created_at__hour": "date",
    "orders.created_at__minute": "date",
    "orders.created_at__month": "date",
    "orders.created_at__quarter": "date",
    "orders.created_at__second": "date",
    "orders.created_at__week": "date",
    "orders.created_at__year": "date",
    "orders.customer_tier": "string",
    "orders.gross_margin": "number",
    "orders.order_count": "number",
    "orders.product_line": "string",
    "orders.region": "string",
    "orders.revenue": "number"
  }
} as const;

export type SidemanticSchema = typeof sidemanticSchema;
export type Metric = typeof sidemanticSchema.metrics[number];
export type Dimension = typeof sidemanticSchema.dimensions[number];
export type SemanticField = typeof sidemanticSchema.fields[number];
export type DashboardRenderer = "vega-lite" | "plotly" | "observable-plot" | "d3" | "crossfilter";
export type ChartType = "auto" | "bar" | "line" | "area" | "scatter" | "point";

export interface FieldValueMap {
  "orders.channel": string;
  "orders.created_at": string | Date;
  "orders.created_at__day": string | Date;
  "orders.created_at__hour": string | Date;
  "orders.created_at__minute": string | Date;
  "orders.created_at__month": string | Date;
  "orders.created_at__quarter": string | Date;
  "orders.created_at__second": string | Date;
  "orders.created_at__week": string | Date;
  "orders.created_at__year": string | Date;
  "orders.customer_tier": string;
  "orders.gross_margin": number;
  "orders.order_count": number;
  "orders.product_line": string;
  "orders.region": string;
  "orders.revenue": number;
}

export type FieldValue<F extends SemanticField> = F extends keyof FieldValueMap ? FieldValueMap[F] : never;

export type DashboardConfig = {
  schema?: "sidemantic.dashboard.v1";
  title: string;
  defaults?: DashboardDefaults;
  tabs: readonly DashboardTab[];
};

export type DashboardDefaults = {
  renderer?: DashboardRenderer;
  query?: {
    interactionPreaggregations?: boolean;
    interaction_preaggregations?: boolean;
    usePreaggregations?: boolean;
    use_preaggregations?: boolean;
  };
  interactions?: {
    scope?: "chart" | "tab" | "dashboard";
  };
};

export type DashboardTab = {
  id: string;
  label?: string;
  sourceRecordCount?: number;
  source_record_count?: number;
  charts: readonly DashboardChart[];
};

export type DashboardChart = {
  id: string;
  title?: string;
  type?: ChartType;
  renderer?: DashboardRenderer;
  tableLimit?: number;
  table_limit?: number;
  sourceRecordCount?: number;
  source_record_count?: number;
  query: ChartQuery;
  encoding?: ChartEncoding;
  interactions?: ChartInteractions;
};

export type ChartQuery = {
  metrics: readonly Metric[];
  dimensions?: readonly Dimension[];
  filters?: readonly string[];
  segments?: readonly string[];
  orderBy?: readonly SemanticField[];
  order_by?: readonly SemanticField[];
  limit?: number;
  interactionPreaggregations?: boolean;
  interaction_preaggregations?: boolean;
  usePreaggregations?: boolean;
  use_preaggregations?: boolean;
};

export type ChartEncoding = {
  x?: SemanticField;
  y?: Metric | readonly Metric[];
  color?: Dimension;
  size?: Metric;
  facet?: Dimension;
};

export type ChartInteractions = {
  crossfilter?: boolean;
  brush?: boolean | {
    fields?: readonly SemanticField[];
    channel?: "x" | "y" | "xy";
  };
  select?: boolean | {
    fields?: readonly SemanticField[];
  };
};

export function defineDashboard<const T extends DashboardConfig>(dashboard: T): T {
  return dashboard;
}
