-- 005: Address mappings (translate-service core)
CREATE TABLE IF NOT EXISTS address_mappings (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
    internal_address VARCHAR(128) NOT NULL,
    chain_address VARCHAR(128) NOT NULL,
    chain_type VARCHAR(20) NOT NULL,
    is_active BOOLEAN NOT NULL DEFAULT TRUE,
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE UNIQUE INDEX IF NOT EXISTS idx_address_mappings_internal ON address_mappings(internal_address);
CREATE INDEX IF NOT EXISTS idx_address_mappings_chain ON address_mappings(chain_type, chain_address);
CREATE INDEX IF NOT EXISTS idx_address_mappings_user ON address_mappings(user_id);
