{
  "$schema": "mantara.schema.v1",
  "system_name": "ASN Workflow",
  "schema_name": "asn_workflow",
  "description": "Supports core operations in logistics, managing ASNs and related processes.",
  "menus": [
    {
      "menu_id": 1,
      "menu_name": "Core Operations",
      "sequence_number": 1,
      "description": "Manage core logistics operations including ASNs and receiving confirmations.",
      "submenus": [
        {
          "submenu_id": 101,
          "submenu_name": "Advanced Shipment Notice Management",
          "sequence_number": 1,
          "description": "Manage advanced shipment notices.",
          "tables": [
            {
              "table_name": "advanced_shipment_notice",
              "comment": "Stores advanced shipment notices sent by suppliers announcing inbound goods.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 101 NOT NULL REFERENCES asn_workflow.submenu(submenu_id)"
                },
                {
                  "name": "asn_id",
                  "type": "VARCHAR(255)",
                  "constraints": "NOT NULL UNIQUE",
                  "comment": "was: asnId"
                },
                {
                  "name": "supplier_id",
                  "type": "UUID",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "status_id",
                  "type": "INT",
                  "constraints": "NOT NULL REFERENCES asn_workflow.cfg_advanced_shipment_notice_status(cfg_advanced_shipment_notice_status_id)"
                },
                {
                  "name": "version",
                  "type": "INT",
                  "constraints": "NOT NULL DEFAULT 1",
                  "comment": "Optimistic-concurrency version counter"
                },
                {
                  "name": "notes",
                  "type": "TEXT",
                  "comment": "Free-form operator notes"
                },
                {
                  "name": "metadata",
                  "type": "JSONB",
                  "comment": "Variable-shape extension payload"
                },
                {
                  "name": "deleted_at",
                  "type": "TIMESTAMP",
                  "comment": "Soft-delete marker (NULL = not deleted)"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMPTZ",
                  "constraints": "DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMPTZ",
                  "constraints": "DEFAULT CURRENT_TIMESTAMP"
                }
              ],
              "foreign_keys": [
                {
                  "column": "supplier_id",
                  "references": "asn_workflow.supplier(id)",
                  "on_delete": "RESTRICT",
                  "on_update": "CASCADE"
                }
              ]
            }
          ]
        },
        {
          "submenu_id": 102,
          "submenu_name": "Receiving Confirmation Management",
          "sequence_number": 2,
          "description": "Manage receiving confirmation reports.",
          "tables": [
            {
              "table_name": "receiving_confirmation_report",
              "comment": "Stores official documents confirming receipt of goods.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 102 NOT NULL REFERENCES asn_workflow.submenu(submenu_id)"
                },
                {
                  "name": "rcr_id",
                  "type": "VARCHAR(255)",
                  "constraints": "NOT NULL",
                  "comment": "was: rcrId"
                },
                {
                  "name": "sku_details",
                  "type": "JSONB",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "vendor_details",
                  "type": "JSONB",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "version",
                  "type": "INT",
                  "constraints": "NOT NULL DEFAULT 1",
                  "comment": "Optimistic-concurrency version counter"
                },
                {
                  "name": "notes",
                  "type": "TEXT",
                  "comment": "Free-form operator notes"
                },
                {
                  "name": "metadata",
                  "type": "JSONB",
                  "comment": "Variable-shape extension payload"
                },
                {
                  "name": "deleted_at",
                  "type": "TIMESTAMP",
                  "comment": "Soft-delete marker (NULL = not deleted)"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMPTZ",
                  "constraints": "DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMPTZ",
                  "constraints": "DEFAULT CURRENT_TIMESTAMP"
                }
              ],
              "foreign_keys": []
            }
          ]
        }
      ]
    },
    {
      "menu_id": 2,
      "menu_name": "Master Data & Catalog",
      "sequence_number": 2,
      "description": "Manage master data including ASN line items and suppliers.",
      "submenus": [
        {
          "submenu_id": 201,
          "submenu_name": "ASN Line Item Management",
          "sequence_number": 1,
          "description": "Manage line items within ASNs.",
          "tables": [
            {
              "table_name": "asn_line_item",
              "comment": "Stores line items within an ASN.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 201 NOT NULL REFERENCES asn_workflow.submenu(submenu_id)"
                },
                {
                  "name": "sku",
                  "type": "VARCHAR(255)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "quantity",
                  "type": "INT",
                  "constraints": "NOT NULL CHECK (quantity > 0)"
                },
                {
                  "name": "po_number",
                  "type": "VARCHAR(255)",
                  "constraints": "NOT NULL",
                  "comment": "was: poNumber"
                },
                {
                  "name": "upc_number",
                  "type": "VARCHAR(255)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "version",
                  "type": "INT",
                  "constraints": "NOT NULL DEFAULT 1",
                  "comment": "Optimistic-concurrency version counter"
                },
                {
                  "name": "notes",
                  "type": "TEXT",
                  "comment": "Free-form operator notes"
                },
                {
                  "name": "metadata",
                  "type": "JSONB",
                  "comment": "Variable-shape extension payload"
                },
                {
                  "name": "deleted_at",
                  "type": "TIMESTAMP",
                  "comment": "Soft-delete marker (NULL = not deleted)"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMPTZ",
                  "constraints": "DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMPTZ",
                  "constraints": "DEFAULT CURRENT_TIMESTAMP"
                }
              ],
              "foreign_keys": [
                {
                  "column": "asn_id",
                  "references": "asn_workflow.advanced_shipment_notice(id)",
                  "on_delete": "CASCADE",
                  "on_update": "CASCADE"
                }
              ]
            }
          ]
        },
        {
          "submenu_id": 202,
          "submenu_name": "Supplier Management",
          "sequence_number": 2,
          "description": "Manage suppliers providing goods.",
          "tables": [
            {
              "table_name": "supplier",
              "comment": "Stores information about suppliers providing goods.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 202 NOT NULL REFERENCES asn_workflow.submenu(submenu_id)"
                },
                {
                  "name": "status_id",
                  "type": "INT",
                  "constraints": "NOT NULL DEFAULT 1 REFERENCES asn_workflow.cfg_supplier_status(cfg_supplier_status_id)",
                  "comment": "Auto-injected: archetype_default"
                },
                {
                  "name": "supplier_id",
                  "type": "UUID",
                  "constraints": "NOT NULL UNIQUE",
                  "comment": "was: supplierId"
                },
                {
                  "name": "supplier_name",
                  "type": "VARCHAR(255)",
                  "constraints": "NOT NULL",
                  "comment": "was: supplierName"
                },
                {
                  "name": "version",
                  "type": "INT",
                  "constraints": "NOT NULL DEFAULT 1",
                  "comment": "Optimistic-concurrency version counter"
                },
                {
                  "name": "notes",
                  "type": "TEXT",
                  "comment": "Free-form operator notes"
                },
                {
                  "name": "metadata",
                  "type": "JSONB",
                  "comment": "Variable-shape extension payload"
                },
                {
                  "name": "deleted_at",
                  "type": "TIMESTAMP",
                  "comment": "Soft-delete marker (NULL = not deleted)"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMPTZ",
                  "constraints": "DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMPTZ",
                  "constraints": "DEFAULT CURRENT_TIMESTAMP"
                }
              ],
              "foreign_keys": []
            }
          ]
        }
      ]
    },
    {
      "menu_id": 3,
      "menu_name": "Reports & History",
      "sequence_number": 3,
      "description": "Access reports and historical data.",
      "submenus": [
        {
          "submenu_id": 301,
          "submenu_name": "Door Management",
          "sequence_number": 1,
          "description": "Manage door assignments.",
          "tables": [
            {
              "table_name": "door_master",
              "comment": "Stores master data for door assignments.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 301 NOT NULL REFERENCES asn_workflow.submenu(submenu_id)"
                },
                {
                  "name": "door_number",
                  "type": "VARCHAR(255)",
                  "constraints": "NOT NULL",
                  "comment": "was: doorNumber"
                },
                {
                  "name": "version",
                  "type": "INT",
                  "constraints": "NOT NULL DEFAULT 1",
                  "comment": "Optimistic-concurrency version counter"
                },
                {
                  "name": "notes",
                  "type": "TEXT",
                  "comment": "Free-form operator notes"
                },
                {
                  "name": "metadata",
                  "type": "JSONB",
                  "comment": "Variable-shape extension payload"
                },
                {
                  "name": "deleted_at",
                  "type": "TIMESTAMP",
                  "comment": "Soft-delete marker (NULL = not deleted)"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMPTZ",
                  "constraints": "DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMPTZ",
                  "constraints": "DEFAULT CURRENT_TIMESTAMP"
                }
              ],
              "foreign_keys": []
            }
          ]
        }
      ]
    },
    {
      "menu_id": 4,
      "menu_name": "User Management",
      "sequence_number": 4,
      "description": "Manage users, roles, and permissions.",
      "submenus": [
        {
          "submenu_id": 401,
          "submenu_name": "User Directory",
          "sequence_number": 1,
          "description": "Manage user accounts.",
          "tables": [
            {
              "table_name": "users",
              "comment": "Stores user account information.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 401 NOT NULL REFERENCES asn_workflow.submenu(submenu_id)"
                },
                {
                  "name": "status_id",
                  "type": "INT",
                  "constraints": "NOT NULL DEFAULT 1 REFERENCES asn_workflow.cfg_users_status(cfg_users_status_id)",
                  "comment": "Auto-injected: archetype_default"
                },
                {
                  "name": "username",
                  "type": "VARCHAR(255)",
                  "constraints": "NOT NULL UNIQUE"
                },
                {
                  "name": "email",
                  "type": "VARCHAR(255)",
                  "constraints": "NOT NULL UNIQUE CHECK (email LIKE '%@%')"
                },
                {
                  "name": "password_hash",
                  "type": "VARCHAR(255)",
                  "constraints": "NOT NULL",
                  "comment": "Stores bcrypt hash, never plain text"
                },
                {
                  "name": "version",
                  "type": "INT",
                  "constraints": "NOT NULL DEFAULT 1",
                  "comment": "Optimistic-concurrency version counter"
                },
                {
                  "name": "notes",
                  "type": "TEXT",
                  "comment": "Free-form operator notes"
                },
                {
                  "name": "metadata",
                  "type": "JSONB",
                  "comment": "Variable-shape extension payload"
                },
                {
                  "name": "deleted_at",
                  "type": "TIMESTAMP",
                  "comment": "Soft-delete marker (NULL = not deleted)"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMPTZ",
                  "constraints": "DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMPTZ",
                  "constraints": "DEFAULT CURRENT_TIMESTAMP"
                }
              ],
              "foreign_keys": []
            }
          ]
        }
      ]
    },
    {
      "menu_id": 5,
      "menu_name": "Notifications & Audit",
      "sequence_number": 5,
      "description": "Manage notifications and audit logs.",
      "submenus": [
        {
          "submenu_id": 501,
          "submenu_name": "Notifications",
          "sequence_number": 1,
          "description": "Manage system notifications.",
          "tables": [
            {
              "table_name": "notifications",
              "comment": "Stores system notifications for users.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 501 NOT NULL REFERENCES asn_workflow.submenu(submenu_id)"
                },
                {
                  "name": "message",
                  "type": "TEXT",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "user_id",
                  "type": "UUID",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "version",
                  "type": "INT",
                  "constraints": "NOT NULL DEFAULT 1",
                  "comment": "Optimistic-concurrency version counter"
                },
                {
                  "name": "notes",
                  "type": "TEXT",
                  "comment": "Free-form operator notes"
                },
                {
                  "name": "metadata",
                  "type": "JSONB",
                  "comment": "Variable-shape extension payload"
                },
                {
                  "name": "deleted_at",
                  "type": "TIMESTAMP",
                  "comment": "Soft-delete marker (NULL = not deleted)"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMPTZ",
                  "constraints": "DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMPTZ",
                  "constraints": "DEFAULT CURRENT_TIMESTAMP"
                }
              ],
              "foreign_keys": [
                {
                  "column": "user_id",
                  "references": "asn_workflow.users(id)",
                  "on_delete": "CASCADE",
                  "on_update": "CASCADE"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "menu_id": 6,
      "menu_name": "Configuration",
      "sequence_number": 6,
      "description": "Configure system settings and lookup tables.",
      "submenus": [
        {
          "submenu_id": 608,
          "submenu_name": "Cfg Advanced Shipment Notice Status",
          "sequence_number": 8,
          "description": "Status values for advanced shipment notices.",
          "tables": [
            {
              "table_name": "cfg_advanced_shipment_notice_status",
              "comment": "Status values for advanced shipment notices.",
              "columns": [
                {
                  "name": "cfg_advanced_shipment_notice_status_id",
                  "type": "SERIAL",
                  "constraints": "PRIMARY KEY"
                },
                {
                  "name": "code",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL UNIQUE"
                },
                {
                  "name": "label",
                  "type": "VARCHAR(100)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "description",
                  "type": "TEXT"
                },
                {
                  "name": "is_active",
                  "type": "BOOLEAN",
                  "constraints": "NOT NULL DEFAULT TRUE"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "NOT NULL DEFAULT 608 REFERENCES asn_workflow.submenu(submenu_id)"
                }
              ],
              "foreign_keys": []
            }
          ]
        }
      ]
    }
  ],
  "assumptions": [
    "Each entity from explicit and implicit entities is mapped to a table.",
    "The configuration menu will handle all settings and lookup tables.",
    "The system will use UUIDs for primary keys and foreign keys.",
    "All timestamps are stored in TIMESTAMPTZ for consistency across time zones."
  ],
  "open_questions": [
    "Clarification needed on specific business logic for transitions in workflows.",
    "Details on user roles and permissions for specific actions need further elaboration.",
    "Confirmation on the use of JSONB for storing complex data structures like skuDetails and vendorDetails."
  ]
}
