-- +goose Up
-- +goose StatementBegin
ALTER TABLE payout_accounts
    ADD COLUMN IF NOT EXISTS status VARCHAR(32) NOT NULL DEFAULT 'pending',
    ADD COLUMN IF NOT EXISTS reviewed_by BIGINT NOT NULL DEFAULT 0,
    ADD COLUMN IF NOT EXISTS reviewed_at TIMESTAMPTZ,
    ADD COLUMN IF NOT EXISTS review_reason VARCHAR(255) NOT NULL DEFAULT '';

COMMENT ON COLUMN payout_accounts.status IS '结算账户审核状态；用途：控制提现账户可用性；默认 pending。';
COMMENT ON COLUMN payout_accounts.reviewed_by IS '结算账户审核操作者ID；用途：审计追踪；默认 0 表示未审核。';
COMMENT ON COLUMN payout_accounts.reviewed_at IS '结算账户审核时间；用途：记录审核完成时间；未审核为空。';
COMMENT ON COLUMN payout_accounts.review_reason IS '结算账户审核说明；用途：驳回原因或备注；默认空字符串。';

-- 历史数据默认视为已审核通过，避免新增流程影响既有提现。
UPDATE payout_accounts
SET status = 'approved'
WHERE status = 'pending';

CREATE INDEX IF NOT EXISTS payout_accounts_status_idx ON payout_accounts(status);
CREATE INDEX IF NOT EXISTS payout_accounts_reviewed_at_idx ON payout_accounts(reviewed_at);
-- +goose StatementEnd

-- +goose Down
-- +goose StatementBegin
DROP INDEX IF EXISTS payout_accounts_reviewed_at_idx;
DROP INDEX IF EXISTS payout_accounts_status_idx;

ALTER TABLE payout_accounts
    DROP COLUMN IF EXISTS review_reason,
    DROP COLUMN IF EXISTS reviewed_at,
    DROP COLUMN IF EXISTS reviewed_by,
    DROP COLUMN IF EXISTS status;
-- +goose StatementEnd
