-- +goose Up
-- +goose StatementBegin
CREATE TABLE IF NOT EXISTS recharge_codes(
    id bigserial PRIMARY KEY,
    code varchar(64) NOT NULL,
    amount bigint NOT NULL,
    status varchar(32) DEFAULT 'inactive',
    activated_by bigint DEFAULT 0,
    activated_at timestamp with time zone,
    redeemed_by bigint DEFAULT 0,
    redeemed_at timestamp with time zone,
    redeemed_order_id bigint DEFAULT 0,
    remark varchar(255) DEFAULT '',
    created_at timestamp with time zone DEFAULT NOW(),
    updated_at timestamp with time zone DEFAULT NOW(),
    UNIQUE (code)
);

CREATE INDEX IF NOT EXISTS idx_recharge_codes_status ON recharge_codes(status);
CREATE INDEX IF NOT EXISTS idx_recharge_codes_activated_at ON recharge_codes(activated_at);
CREATE INDEX IF NOT EXISTS idx_recharge_codes_redeemed_at ON recharge_codes(redeemed_at);
CREATE INDEX IF NOT EXISTS idx_recharge_codes_redeemed_by ON recharge_codes(redeemed_by);
CREATE INDEX IF NOT EXISTS idx_recharge_codes_redeemed_order ON recharge_codes(redeemed_order_id);
-- +goose StatementEnd

-- +goose Down
-- +goose StatementBegin
DROP TABLE IF EXISTS recharge_codes;
-- +goose StatementEnd
