{
  "$schema": "mantara.schema.v1",
  "system_name": "Pokemon Card Resell Platform",
  "schema_name": "ai_sch_20260513_030544",
  "description": "A specialized e-commerce marketplace for buying, selling, and trading Pokemon trading cards.",
  "menus": [
    {
      "menu_id": 1,
      "menu_name": "User Management",
      "sequence_number": 1,
      "description": "Manage user accounts, profiles, and roles.",
      "submenus": [
        {
          "submenu_id": 101,
          "submenu_name": "User Registration & Authentication",
          "sequence_number": 1,
          "description": "Handles user registration, login, and authentication.",
          "tables": [
            {
              "table_name": "users",
              "comment": "Stores registered users with authentication credentials and profile information.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 101 NOT NULL REFERENCES pcrp.submenu(submenu_id)"
                },
                {
                  "name": "email",
                  "type": "VARCHAR(255)",
                  "constraints": "NOT NULL UNIQUE"
                },
                {
                  "name": "password_hash",
                  "type": "VARCHAR(255)",
                  "constraints": "NOT NULL",
                  "comment": "Stores bcrypt hash, never plain text"
                },
                {
                  "name": "first_name",
                  "type": "VARCHAR(100)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "last_name",
                  "type": "VARCHAR(100)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "phone",
                  "type": "VARCHAR(20)"
                },
                {
                  "name": "avatar_url",
                  "type": "TEXT"
                },
                {
                  "name": "is_email_verified",
                  "type": "BOOLEAN",
                  "constraints": "NOT NULL DEFAULT FALSE"
                },
                {
                  "name": "is_active",
                  "type": "BOOLEAN",
                  "constraints": "NOT NULL DEFAULT TRUE"
                },
                {
                  "name": "role",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL CHECK (role IN ('buyer','seller','admin')) DEFAULT 'buyer'"
                },
                {
                  "name": "last_login_at",
                  "type": "TIMESTAMP"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ]
            }
          ]
        },
        {
          "submenu_id": 102,
          "submenu_name": "Seller Profile Management",
          "sequence_number": 2,
          "description": "Manages seller-specific profiles and settings.",
          "tables": [
            {
              "table_name": "seller_profiles",
              "comment": "Stores additional profile information for users who are sellers.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 102 NOT NULL REFERENCES pcrp.submenu(submenu_id)"
                },
                {
                  "name": "user_id",
                  "type": "UUID",
                  "constraints": "NOT NULL UNIQUE REFERENCES pcrp.users(id) ON DELETE CASCADE"
                },
                {
                  "name": "business_name",
                  "type": "VARCHAR(255)"
                },
                {
                  "name": "bio",
                  "type": "TEXT"
                },
                {
                  "name": "logo_url",
                  "type": "TEXT"
                },
                {
                  "name": "banner_url",
                  "type": "TEXT"
                },
                {
                  "name": "average_rating",
                  "type": "DECIMAL(3,2)",
                  "constraints": "DEFAULT 0.00"
                },
                {
                  "name": "total_sales",
                  "type": "INTEGER",
                  "constraints": "NOT NULL DEFAULT 0"
                },
                {
                  "name": "return_policy",
                  "type": "TEXT"
                },
                {
                  "name": "shipping_policy",
                  "type": "TEXT"
                },
                {
                  "name": "payout_email",
                  "type": "VARCHAR(255)"
                },
                {
                  "name": "is_verified",
                  "type": "BOOLEAN",
                  "constraints": "NOT NULL DEFAULT FALSE"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "menu_id": 2,
      "menu_name": "Card Database",
      "sequence_number": 2,
      "description": "Manage the master data for Pokemon cards and sets.",
      "submenus": [
        {
          "submenu_id": 201,
          "submenu_name": "Card Management",
          "sequence_number": 1,
          "description": "Handles the master data for individual Pokemon cards.",
          "tables": [
            {
              "table_name": "cards",
              "comment": "Stores master data for Pokemon cards including attributes and official images.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 201 NOT NULL REFERENCES pcrp.submenu(submenu_id)"
                },
                {
                  "name": "card_set_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES pcrp.card_sets(id) ON DELETE CASCADE"
                },
                {
                  "name": "name",
                  "type": "VARCHAR(255)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "card_number",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "rarity",
                  "type": "VARCHAR(100)"
                },
                {
                  "name": "card_type",
                  "type": "VARCHAR(100)"
                },
                {
                  "name": "hp",
                  "type": "INTEGER"
                },
                {
                  "name": "artist",
                  "type": "VARCHAR(255)"
                },
                {
                  "name": "official_image_url",
                  "type": "TEXT"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ]
            }
          ]
        },
        {
          "submenu_id": 202,
          "submenu_name": "Card Set Management",
          "sequence_number": 2,
          "description": "Handles the organization and management of card sets.",
          "tables": [
            {
              "table_name": "card_sets",
              "comment": "Stores information about Pokemon card sets including release dates and symbols.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 202 NOT NULL REFERENCES pcrp.submenu(submenu_id)"
                },
                {
                  "name": "name",
                  "type": "VARCHAR(255)",
                  "constraints": "NOT NULL UNIQUE"
                },
                {
                  "name": "series",
                  "type": "VARCHAR(255)"
                },
                {
                  "name": "release_date",
                  "type": "DATE"
                },
                {
                  "name": "total_cards",
                  "type": "INTEGER"
                },
                {
                  "name": "set_code",
                  "type": "VARCHAR(50)",
                  "constraints": "UNIQUE"
                },
                {
                  "name": "symbol_url",
                  "type": "TEXT"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ]
            }
          ]
        },
        {
          "submenu_id": 203,
          "submenu_name": "Card Category Management",
          "sequence_number": 3,
          "description": "Manages the categorization of cards into various categories.",
          "tables": [
            {
              "table_name": "categories",
              "comment": "Stores categories for organizing cards, supporting hierarchical structures.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 203 NOT NULL REFERENCES pcrp.submenu(submenu_id)"
                },
                {
                  "name": "name",
                  "type": "VARCHAR(100)",
                  "constraints": "NOT NULL UNIQUE"
                },
                {
                  "name": "slug",
                  "type": "VARCHAR(100)",
                  "constraints": "NOT NULL UNIQUE"
                },
                {
                  "name": "description",
                  "type": "TEXT"
                },
                {
                  "name": "parent_id",
                  "type": "UUID",
                  "constraints": "REFERENCES pcrp.categories(id) ON DELETE SET NULL"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ]
            },
            {
              "table_name": "card_categories",
              "comment": "Associates cards with categories for organizational purposes.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 203 NOT NULL REFERENCES pcrp.submenu(submenu_id)"
                },
                {
                  "name": "card_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES pcrp.cards(id) ON DELETE CASCADE"
                },
                {
                  "name": "category_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES pcrp.categories(id) ON DELETE CASCADE"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "menu_id": 3,
      "menu_name": "Marketplace",
      "sequence_number": 3,
      "description": "Facilitates the buying, selling, and trading of cards.",
      "submenus": [
        {
          "submenu_id": 301,
          "submenu_name": "Listing Management",
          "sequence_number": 1,
          "description": "Manages the creation and maintenance of card listings.",
          "tables": [
            {
              "table_name": "listings",
              "comment": "Stores listings of cards for sale by sellers, including pricing and condition.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 301 NOT NULL REFERENCES pcrp.submenu(submenu_id)"
                },
                {
                  "name": "seller_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES pcrp.users(id) ON DELETE CASCADE"
                },
                {
                  "name": "card_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES pcrp.cards(id) ON DELETE CASCADE"
                },
                {
                  "name": "card_condition_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES pcrp.card_conditions(id) ON DELETE RESTRICT"
                },
                {
                  "name": "title",
                  "type": "VARCHAR(255)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "description",
                  "type": "TEXT"
                },
                {
                  "name": "price",
                  "type": "DECIMAL(10,2)",
                  "constraints": "NOT NULL CHECK (price >= 0)"
                },
                {
                  "name": "quantity",
                  "type": "INTEGER",
                  "constraints": "NOT NULL DEFAULT 1 CHECK (quantity >= 0)"
                },
                {
                  "name": "is_graded",
                  "type": "BOOLEAN",
                  "constraints": "NOT NULL DEFAULT FALSE"
                },
                {
                  "name": "grading_company",
                  "type": "VARCHAR(100)"
                },
                {
                  "name": "grade",
                  "type": "VARCHAR(50)"
                },
                {
                  "name": "status",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL CHECK (status IN ('draft','active','sold','inactive','deleted')) DEFAULT 'active'"
                },
                {
                  "name": "views_count",
                  "type": "INTEGER",
                  "constraints": "NOT NULL DEFAULT 0"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ]
            },
            {
              "table_name": "listing_images",
              "comment": "Stores images associated with listings, including primary and additional images.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 301 NOT NULL REFERENCES pcrp.submenu(submenu_id)"
                },
                {
                  "name": "listing_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES pcrp.listings(id) ON DELETE CASCADE"
                },
                {
                  "name": "image_url",
                  "type": "TEXT",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "display_order",
                  "type": "INTEGER",
                  "constraints": "NOT NULL DEFAULT 0"
                },
                {
                  "name": "is_primary",
                  "type": "BOOLEAN",
                  "constraints": "NOT NULL DEFAULT FALSE"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ]
            }
          ]
        },
        {
          "submenu_id": 302,
          "submenu_name": "Cart Management",
          "sequence_number": 2,
          "description": "Handles the management of user shopping carts.",
          "tables": [
            {
              "table_name": "carts",
              "comment": "Stores active shopping carts for users.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 302 NOT NULL REFERENCES pcrp.submenu(submenu_id)"
                },
                {
                  "name": "user_id",
                  "type": "UUID",
                  "constraints": "NOT NULL UNIQUE REFERENCES pcrp.users(id) ON DELETE CASCADE"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ]
            },
            {
              "table_name": "cart_items",
              "comment": "Stores items within a user's cart, including quantity and listing reference.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 302 NOT NULL REFERENCES pcrp.submenu(submenu_id)"
                },
                {
                  "name": "cart_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES pcrp.carts(id) ON DELETE CASCADE"
                },
                {
                  "name": "listing_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES pcrp.listings(id) ON DELETE CASCADE"
                },
                {
                  "name": "quantity",
                  "type": "INTEGER",
                  "constraints": "NOT NULL DEFAULT 1 CHECK (quantity > 0)"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "menu_id": 4,
      "menu_name": "Order Management",
      "sequence_number": 4,
      "description": "Manages the processing and fulfillment of orders.",
      "submenus": [
        {
          "submenu_id": 401,
          "submenu_name": "Order Processing",
          "sequence_number": 1,
          "description": "Handles the creation and tracking of orders.",
          "tables": [
            {
              "table_name": "orders",
              "comment": "Stores order details including buyer, shipping, and payment information.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 401 NOT NULL REFERENCES pcrp.submenu(submenu_id)"
                },
                {
                  "name": "buyer_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES pcrp.users(id) ON DELETE RESTRICT"
                },
                {
                  "name": "shipping_address_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES pcrp.shipping_addresses(id) ON DELETE RESTRICT"
                },
                {
                  "name": "order_number",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL UNIQUE"
                },
                {
                  "name": "subtotal",
                  "type": "DECIMAL(10,2)",
                  "constraints": "NOT NULL CHECK (subtotal >= 0)"
                },
                {
                  "name": "shipping_cost",
                  "type": "DECIMAL(10,2)",
                  "constraints": "NOT NULL DEFAULT 0.00 CHECK (shipping_cost >= 0)"
                },
                {
                  "name": "tax",
                  "type": "DECIMAL(10,2)",
                  "constraints": "NOT NULL DEFAULT 0.00 CHECK (tax >= 0)"
                },
                {
                  "name": "total",
                  "type": "DECIMAL(10,2)",
                  "constraints": "NOT NULL CHECK (total >= 0)"
                },
                {
                  "name": "status",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL CHECK (status IN ('pending','paid','processing','shipped','delivered','cancelled','refunded')) DEFAULT 'pending'"
                },
                {
                  "name": "tracking_number",
                  "type": "VARCHAR(255)"
                },
                {
                  "name": "shipped_at",
                  "type": "TIMESTAMP"
                },
                {
                  "name": "delivered_at",
                  "type": "TIMESTAMP"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ]
            },
            {
              "table_name": "order_items",
              "comment": "Stores individual items within an order, including pricing and status.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 401 NOT NULL REFERENCES pcrp.submenu(submenu_id)"
                },
                {
                  "name": "order_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES pcrp.orders(id) ON DELETE CASCADE"
                },
                {
                  "name": "listing_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES pcrp.listings(id) ON DELETE RESTRICT"
                },
                {
                  "name": "seller_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES pcrp.users(id) ON DELETE RESTRICT"
                },
                {
                  "name": "quantity",
                  "type": "INTEGER",
                  "constraints": "NOT NULL CHECK (quantity > 0)"
                },
                {
                  "name": "price_per_unit",
                  "type": "DECIMAL(10,2)",
                  "constraints": "NOT NULL CHECK (price_per_unit >= 0)"
                },
                {
                  "name": "total_price",
                  "type": "DECIMAL(10,2)",
                  "constraints": "NOT NULL CHECK (total_price >= 0)"
                },
                {
                  "name": "status",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL CHECK (status IN ('pending','processing','shipped','delivered','cancelled','refunded')) DEFAULT 'pending'"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "menu_id": 5,
      "menu_name": "Financial Management",
      "sequence_number": 5,
      "description": "Handles financial transactions, payments, and refunds.",
      "submenus": [
        {
          "submenu_id": 501,
          "submenu_name": "Payment Processing",
          "sequence_number": 1,
          "description": "Manages payment transactions and methods.",
          "tables": [
            {
              "table_name": "payments",
              "comment": "Records payment transactions for orders, including status and method.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 501 NOT NULL REFERENCES pcrp.submenu(submenu_id)"
                },
                {
                  "name": "order_id",
                  "type": "UUID",
                  "constraints": "NOT NULL UNIQUE REFERENCES pcrp.orders(id) ON DELETE RESTRICT"
                },
                {
                  "name": "amount",
                  "type": "DECIMAL(10,2)",
                  "constraints": "NOT NULL CHECK (amount >= 0)"
                },
                {
                  "name": "payment_method",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL CHECK (payment_method IN ('credit_card','debit_card','paypal','stripe','other'))"
                },
                {
                  "name": "transaction_id",
                  "type": "VARCHAR(255)",
                  "constraints": "UNIQUE"
                },
                {
                  "name": "status",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL CHECK (status IN ('pending','completed','failed','refunded','cancelled')) DEFAULT 'pending'"
                },
                {
                  "name": "payment_gateway",
                  "type": "VARCHAR(100)"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ]
            },
            {
              "table_name": "saved_payment_methods",
              "comment": "Stores tokenized payment methods for quick checkout by users.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 501 NOT NULL REFERENCES pcrp.submenu(submenu_id)"
                },
                {
                  "name": "user_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES pcrp.users(id) ON DELETE CASCADE"
                },
                {
                  "name": "payment_type",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL CHECK (payment_type IN ('credit_card','debit_card','paypal'))"
                },
                {
                  "name": "token",
                  "type": "VARCHAR(255)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "last_four",
                  "type": "VARCHAR(4)"
                },
                {
                  "name": "expiry_month",
                  "type": "INTEGER"
                },
                {
                  "name": "expiry_year",
                  "type": "INTEGER"
                },
                {
                  "name": "card_brand",
                  "type": "VARCHAR(50)"
                },
                {
                  "name": "is_default",
                  "type": "BOOLEAN",
                  "constraints": "NOT NULL DEFAULT FALSE"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ]
            }
          ]
        },
        {
          "submenu_id": 502,
          "submenu_name": "Transaction Management",
          "sequence_number": 2,
          "description": "Tracks all financial transactions related to orders and payouts.",
          "tables": [
            {
              "table_name": "transactions",
              "comment": "Logs all financial transactions including sales, refunds, and fees.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 502 NOT NULL REFERENCES pcrp.submenu(submenu_id)"
                },
                {
                  "name": "user_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES pcrp.users(id) ON DELETE RESTRICT"
                },
                {
                  "name": "order_id",
                  "type": "UUID",
                  "constraints": "REFERENCES pcrp.orders(id) ON DELETE RESTRICT"
                },
                {
                  "name": "transaction_type",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL CHECK (transaction_type IN ('sale','refund','fee','payout','credit'))"
                },
                {
                  "name": "amount",
                  "type": "DECIMAL(10,2)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "currency",
                  "type": "VARCHAR(3)",
                  "constraints": "NOT NULL DEFAULT 'USD'"
                },
                {
                  "name": "status",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL CHECK (status IN ('pending','completed','failed','cancelled')) DEFAULT 'pending'"
                },
                {
                  "name": "description",
                  "type": "TEXT"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "menu_id": 6,
      "menu_name": "Communication & Feedback",
      "sequence_number": 6,
      "description": "Manages user interactions, reviews, and messaging.",
      "submenus": [
        {
          "submenu_id": 601,
          "submenu_name": "Review & Rating Management",
          "sequence_number": 1,
          "description": "Handles user reviews and ratings for sellers and transactions.",
          "tables": [
            {
              "table_name": "reviews",
              "comment": "Stores reviews and ratings given by buyers to sellers.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 601 NOT NULL REFERENCES pcrp.submenu(submenu_id)"
                },
                {
                  "name": "order_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES pcrp.orders(id) ON DELETE CASCADE"
                },
                {
                  "name": "reviewer_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES pcrp.users(id) ON DELETE CASCADE"
                },
                {
                  "name": "seller_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES pcrp.users(id) ON DELETE CASCADE"
                },
                {
                  "name": "rating",
                  "type": "INTEGER",
                  "constraints": "NOT NULL CHECK (rating >= 1 AND rating <= 5)"
                },
                {
                  "name": "comment",
                  "type": "TEXT"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ]
            }
          ]
        },
        {
          "submenu_id": 602,
          "submenu_name": "Messaging System",
          "sequence_number": 2,
          "description": "Facilitates communication between buyers and sellers.",
          "tables": [
            {
              "table_name": "messages",
              "comment": "Stores messages exchanged between users regarding listings and orders.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 602 NOT NULL REFERENCES pcrp.submenu(submenu_id)"
                },
                {
                  "name": "sender_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES pcrp.users(id) ON DELETE CASCADE"
                },
                {
                  "name": "recipient_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES pcrp.users(id) ON DELETE CASCADE"
                },
                {
                  "name": "listing_id",
                  "type": "UUID",
                  "constraints": "REFERENCES pcrp.listings(id) ON DELETE SET NULL"
                },
                {
                  "name": "order_id",
                  "type": "UUID",
                  "constraints": "REFERENCES pcrp.orders(id) ON DELETE SET NULL"
                },
                {
                  "name": "subject",
                  "type": "VARCHAR(255)"
                },
                {
                  "name": "body",
                  "type": "TEXT",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "is_read",
                  "type": "BOOLEAN",
                  "constraints": "NOT NULL DEFAULT FALSE"
                },
                {
                  "name": "read_at",
                  "type": "TIMESTAMP"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "menu_id": 7,
      "menu_name": "Wishlist & Offers",
      "sequence_number": 7,
      "description": "Manages user wishlists and offer systems for listings.",
      "submenus": [
        {
          "submenu_id": 701,
          "submenu_name": "Wishlist Management",
          "sequence_number": 1,
          "description": "Handles the creation and management of user wishlists.",
          "tables": [
            {
              "table_name": "wishlists",
              "comment": "Stores user-created wishlists for tracking desired cards or listings.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 701 NOT NULL REFERENCES pcrp.submenu(submenu_id)"
                },
                {
                  "name": "user_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES pcrp.users(id) ON DELETE CASCADE"
                },
                {
                  "name": "name",
                  "type": "VARCHAR(255)",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "is_public",
                  "type": "BOOLEAN",
                  "constraints": "NOT NULL DEFAULT FALSE"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ]
            },
            {
              "table_name": "wishlist_items",
              "comment": "Associates cards or listings with a user's wishlist.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 701 NOT NULL REFERENCES pcrp.submenu(submenu_id)"
                },
                {
                  "name": "wishlist_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES pcrp.wishlists(id) ON DELETE CASCADE"
                },
                {
                  "name": "listing_id",
                  "type": "UUID",
                  "constraints": "REFERENCES pcrp.listings(id) ON DELETE CASCADE"
                },
                {
                  "name": "card_id",
                  "type": "UUID",
                  "constraints": "REFERENCES pcrp.cards(id) ON DELETE CASCADE"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ]
            }
          ]
        },
        {
          "submenu_id": 702,
          "submenu_name": "Offer Management",
          "sequence_number": 2,
          "description": "Manages buyer offers on listings and seller responses.",
          "tables": [
            {
              "table_name": "offers",
              "comment": "Stores offers made by buyers on listings, including status and response.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 702 NOT NULL REFERENCES pcrp.submenu(submenu_id)"
                },
                {
                  "name": "listing_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES pcrp.listings(id) ON DELETE CASCADE"
                },
                {
                  "name": "buyer_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES pcrp.users(id) ON DELETE CASCADE"
                },
                {
                  "name": "offer_amount",
                  "type": "DECIMAL(10,2)",
                  "constraints": "NOT NULL CHECK (offer_amount > 0)"
                },
                {
                  "name": "message",
                  "type": "TEXT"
                },
                {
                  "name": "status",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL CHECK (status IN ('pending','accepted','declined','expired','cancelled')) DEFAULT 'pending'"
                },
                {
                  "name": "expires_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "responded_at",
                  "type": "TIMESTAMP"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ]
            }
          ]
        }
      ]
    },
    {
      "menu_id": 8,
      "menu_name": "Dispute & Resolution",
      "sequence_number": 8,
      "description": "Handles disputes and resolutions between buyers and sellers.",
      "submenus": [
        {
          "submenu_id": 801,
          "submenu_name": "Dispute Management",
          "sequence_number": 1,
          "description": "Manages disputes raised by users and their resolution.",
          "tables": [
            {
              "table_name": "disputes",
              "comment": "Stores disputes raised by users regarding orders, including status and resolution.",
              "columns": [
                {
                  "name": "id",
                  "type": "UUID",
                  "constraints": "PRIMARY KEY DEFAULT gen_random_uuid()"
                },
                {
                  "name": "submenu_id",
                  "type": "INT",
                  "constraints": "DEFAULT 801 NOT NULL REFERENCES pcrp.submenu(submenu_id)"
                },
                {
                  "name": "order_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES pcrp.orders(id) ON DELETE CASCADE"
                },
                {
                  "name": "initiator_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES pcrp.users(id) ON DELETE CASCADE"
                },
                {
                  "name": "respondent_id",
                  "type": "UUID",
                  "constraints": "NOT NULL REFERENCES pcrp.users(id) ON DELETE CASCADE"
                },
                {
                  "name": "reason",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL CHECK (reason IN ('not_received','not_as_described','damaged','counterfeit','other'))"
                },
                {
                  "name": "description",
                  "type": "TEXT",
                  "constraints": "NOT NULL"
                },
                {
                  "name": "status",
                  "type": "VARCHAR(50)",
                  "constraints": "NOT NULL CHECK (status IN ('open','under_review','resolved','closed')) DEFAULT 'open'"
                },
                {
                  "name": "resolution",
                  "type": "TEXT"
                },
                {
                  "name": "resolved_by",
                  "type": "UUID",
                  "constraints": "REFERENCES pcrp.users(id) ON DELETE SET NULL"
                },
                {
                  "name": "resolved_at",
                  "type": "TIMESTAMP"
                },
                {
                  "name": "created_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                },
                {
                  "name": "updated_at",
                  "type": "TIMESTAMP",
                  "constraints": "NOT NULL DEFAULT CURRENT_TIMESTAMP"
                }
              ]
            }
          ]
        }
      ]
    }
  ],
  "assumptions": [
    "Each user can have only one active seller profile.",
    "Listings must reference a valid card from the master card database.",
    "Offers must be less than the current listing price."
  ],
  "open_questions": [
    "Should the system support multi-currency transactions?",
    "Is there a need for role-based access beyond admin/user?"
  ]
}
