{
  "version": "1.0",
  "meta": {
    "name": "库存台账",
    "slug": "inventory_ledger",
    "description": "根据上传的库存 Excel 与「要一个可筛选的库存列表页」描述生成",
    "locale": "zh-CN",
    "source": {
      "prompt": "根据这张库存表生成可筛选、可编辑的数据展示页，支持按仓库和状态过滤",
      "image_refs": ["oss://uploads/u_1001/mockups/inventory-list.png"],
      "excel_ref": "oss://uploads/u_1001/excel/inventory.xlsx"
    },
    "confidence": 0.86
  },
  "storage": {
    "mode": "schema_per_app",
    "engine": "postgres",
    "schema_name": "app_inventory_ledger"
  },
  "entities": [
    {
      "name": "inventory_item",
      "table": "inventory_item",
      "label": "库存明细",
      "primary_key": "id",
      "fields": [
        {
          "name": "id",
          "label": "ID",
          "type": "bigint",
          "nullable": false,
          "ui": { "widget": "hidden", "listable": false }
        },
        {
          "name": "sku",
          "label": "SKU",
          "type": "string",
          "nullable": false,
          "unique": true,
          "max_length": 64,
          "ui": {
            "widget": "input",
            "listable": true,
            "filterable": true,
            "sortable": true,
            "width": "md"
          },
          "from_excel": {
            "column": "SKU",
            "sample_values": ["A-1001", "A-1002", "B-2001"]
          }
        },
        {
          "name": "product_name",
          "label": "商品名称",
          "type": "string",
          "nullable": false,
          "max_length": 128,
          "ui": {
            "widget": "input",
            "listable": true,
            "filterable": true,
            "sortable": true,
            "width": "lg"
          },
          "from_excel": {
            "column": "商品名称",
            "sample_values": ["无线鼠标", "机械键盘", "显示器支架"]
          }
        },
        {
          "name": "warehouse",
          "label": "仓库",
          "type": "enum",
          "nullable": false,
          "enum_values": ["华东仓", "华南仓", "华北仓"],
          "ui": {
            "widget": "select",
            "listable": true,
            "filterable": true,
            "sortable": false,
            "width": "sm"
          },
          "from_excel": {
            "column": "仓库",
            "sample_values": ["华东仓", "华南仓"]
          }
        },
        {
          "name": "qty",
          "label": "库存数量",
          "type": "int",
          "nullable": false,
          "default": 0,
          "ui": {
            "widget": "number",
            "listable": true,
            "filterable": false,
            "sortable": true,
            "width": "sm"
          },
          "from_excel": {
            "column": "数量",
            "sample_values": ["120", "35", "8"]
          }
        },
        {
          "name": "unit_price",
          "label": "单价",
          "type": "decimal",
          "nullable": true,
          "precision": 12,
          "scale": 2,
          "ui": {
            "widget": "number",
            "listable": true,
            "sortable": true,
            "width": "sm"
          },
          "from_excel": {
            "column": "单价",
            "sample_values": ["59.90", "299.00"]
          }
        },
        {
          "name": "status",
          "label": "状态",
          "type": "enum",
          "nullable": false,
          "enum_values": ["在售", "停售", "盘点中"],
          "ui": {
            "widget": "select",
            "listable": true,
            "filterable": true,
            "width": "sm"
          },
          "from_excel": {
            "column": "状态",
            "sample_values": ["在售", "停售"]
          }
        },
        {
          "name": "updated_at",
          "label": "更新时间",
          "type": "datetime",
          "nullable": false,
          "ui": {
            "widget": "datepicker",
            "listable": true,
            "sortable": true,
            "width": "md"
          },
          "from_excel": {
            "column": "更新时间",
            "sample_values": ["2026-07-01 10:00:00"]
          }
        }
      ],
      "indexes": [
        {
          "name": "idx_inventory_item_warehouse_status",
          "columns": ["warehouse", "status"],
          "unique": false
        },
        {
          "name": "idx_inventory_item_sku",
          "columns": ["sku"],
          "unique": true
        }
      ]
    }
  ],
  "apis": {
    "base_path": "/api/v1/apps/inventory_ledger",
    "resources": [
      {
        "entity": "inventory_item",
        "path": "/inventory_items",
        "operations": [
          "list",
          "get",
          "create",
          "update",
          "delete",
          "import",
          "export"
        ],
        "list": {
          "default_page_size": 20,
          "max_page_size": 100,
          "allowed_filters": ["sku", "product_name", "warehouse", "status"],
          "allowed_sorts": ["sku", "qty", "unit_price", "updated_at"]
        }
      }
    ]
  },
  "pages": [
    {
      "id": "inventory_list",
      "title": "库存列表",
      "route": "/inventory",
      "type": "list",
      "entity": "inventory_item",
      "layout": {
        "columns": [
          "sku",
          "product_name",
          "warehouse",
          "qty",
          "unit_price",
          "status",
          "updated_at"
        ],
        "filters": ["warehouse", "status", "sku"],
        "actions": ["create", "edit", "delete", "export", "import", "refresh"]
      }
    },
    {
      "id": "inventory_create",
      "title": "新增库存",
      "route": "/inventory/create",
      "type": "form_create",
      "entity": "inventory_item",
      "layout": {
        "form_fields": [
          "sku",
          "product_name",
          "warehouse",
          "qty",
          "unit_price",
          "status"
        ],
        "actions": ["create"]
      }
    },
    {
      "id": "inventory_edit",
      "title": "编辑库存",
      "route": "/inventory/:id/edit",
      "type": "form_edit",
      "entity": "inventory_item",
      "layout": {
        "form_fields": [
          "sku",
          "product_name",
          "warehouse",
          "qty",
          "unit_price",
          "status"
        ],
        "actions": ["edit"]
      }
    },
    {
      "id": "inventory_dashboard",
      "title": "库存概览",
      "route": "/inventory/dashboard",
      "type": "dashboard",
      "entity": "inventory_item",
      "layout": {
        "widgets": [
          {
            "type": "kpi",
            "title": "SKU 总数",
            "metric": "count",
            "entity": "inventory_item"
          },
          {
            "type": "kpi",
            "title": "总库存量",
            "metric": "sum:qty",
            "entity": "inventory_item"
          },
          {
            "type": "bar_chart",
            "title": "各仓库库存量",
            "metric": "sum:qty",
            "group_by": "warehouse",
            "entity": "inventory_item"
          },
          {
            "type": "pie_chart",
            "title": "状态分布",
            "metric": "count",
            "group_by": "status",
            "entity": "inventory_item"
          }
        ]
      }
    }
  ],
  "security": {
    "visibility": "private",
    "roles": [
      {
        "name": "owner",
        "permissions": [
          "app.read",
          "app.write",
          "app.admin",
          "row.create",
          "row.read",
          "row.update",
          "row.delete",
          "row.export",
          "row.import"
        ]
      },
      {
        "name": "editor",
        "permissions": [
          "app.read",
          "row.create",
          "row.read",
          "row.update",
          "row.export",
          "row.import"
        ]
      },
      {
        "name": "viewer",
        "permissions": ["app.read", "row.read", "row.export"]
      }
    ],
    "row_policies": [
      {
        "entity": "inventory_item",
        "rule": "tenant_isolated"
      }
    ]
  },
  "seed": {
    "import_excel": true,
    "max_rows": 5000
  }
}
