CREATE TABLE IF NOT EXISTS member_orders (
  id INT NOT NULL AUTO_INCREMENT,
  member_id INT NOT NULL,
  club_id INT NOT NULL,
  item VARCHAR(255) NOT NULL,
  status ENUM('requested', 'ordered', 'arrived', 'handed_over') NOT NULL DEFAULT 'requested',
  order_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  status_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  cost DECIMAL(10,2) NOT NULL DEFAULT 0.00,
  paid_amount DECIMAL(10,2) NOT NULL DEFAULT 0.00,
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (id),
  KEY idx_member_orders_member_id (member_id),
  KEY idx_member_orders_club_id (club_id),
  KEY idx_member_orders_status (status)
);

CREATE TABLE IF NOT EXISTS member_order_history (
  id INT NOT NULL AUTO_INCREMENT,
  member_order_id INT NOT NULL,
  member_id INT NOT NULL,
  club_id INT NOT NULL,
  item VARCHAR(255) NOT NULL,
  status ENUM('requested', 'ordered', 'arrived', 'handed_over') NOT NULL,
  changed_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  cost DECIMAL(10,2) NOT NULL DEFAULT 0.00,
  paid_amount DECIMAL(10,2) NOT NULL DEFAULT 0.00,
  created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (id),
  KEY idx_member_order_history_order_id (member_order_id),
  KEY idx_member_order_history_member_id (member_id),
  KEY idx_member_order_history_club_id (club_id),
  KEY idx_member_order_history_changed_at (changed_at)
);
