-- +goose Up
ALTER TABLE order_checkouts
  ADD COLUMN round_count INT NOT NULL DEFAULT 1 COMMENT '结账协商轮次（提交为第1轮）' AFTER status,
  ADD COLUMN turn VARCHAR(16) NOT NULL DEFAULT 'owner' COMMENT '当前待处理方: owner/renter' AFTER round_count,
  ADD COLUMN proposed_by BIGINT UNSIGNED NOT NULL DEFAULT 0 COMMENT '当前提案提出人' AFTER turn,
  ADD COLUMN shortfall_cent BIGINT NOT NULL DEFAULT 0 COMMENT '押金不足以覆盖打超/赔付的差额(分)' AFTER owner_income_amount_cent,
  ADD COLUMN overshoot_amount_cent BIGINT NOT NULL DEFAULT 0 COMMENT '超出预收租金的打超金额(分)' AFTER shortfall_cent;

-- 历史单：已反价等待租客的，轮到租客
UPDATE order_checkouts
SET turn = 'renter', round_count = GREATEST(round_count, 2)
WHERE status = 'countered';

-- +goose Down
ALTER TABLE order_checkouts
  DROP COLUMN overshoot_amount_cent,
  DROP COLUMN shortfall_cent,
  DROP COLUMN proposed_by,
  DROP COLUMN turn,
  DROP COLUMN round_count;
