-- +goose Up

CREATE TABLE admin_pickups (
  id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  pickup_no VARCHAR(64) NOT NULL COMMENT '提号编号 PK+时间+随机',
  listing_id BIGINT UNSIGNED NOT NULL COMMENT '关联的发布项',
  account_id BIGINT UNSIGNED NOT NULL COMMENT '关联的游戏账号',
  owner_id BIGINT UNSIGNED NOT NULL COMMENT '卖家(号主)',
  admin_id BIGINT UNSIGNED NOT NULL COMMENT '操作管理员',
  platform VARCHAR(32) NOT NULL DEFAULT '' COMMENT '线下交易渠道(微信/QQ/闲鱼等)',
  settle_amount_cent BIGINT NOT NULL DEFAULT 0 COMMENT '完成时结算金额(分)',
  status VARCHAR(20) NOT NULL DEFAULT 'picking_up' COMMENT '状态: picking_up提号中/completed已完成/cancelled已取消',
  remark VARCHAR(255) NOT NULL DEFAULT '' COMMENT '创建备注',
  complete_remark VARCHAR(255) NOT NULL DEFAULT '' COMMENT '完成备注',
  created_at DATETIME NOT NULL,
  completed_at DATETIME NULL,
  cancelled_at DATETIME NULL,
  PRIMARY KEY (id),
  UNIQUE KEY uk_pickup_no (pickup_no),
  KEY idx_listing (listing_id),
  KEY idx_owner (owner_id),
  KEY idx_status (status),
  KEY idx_created (created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='管理员线下提号记录，独立于 rental_orders';

INSERT INTO permissions (code, name, resource, action)
VALUES ('order:pickup', '管理员提号', 'order', 'pickup');

-- +goose Down

DROP TABLE IF EXISTS admin_pickups;
DELETE FROM permissions WHERE code = 'order:pickup';
