-- 011: KYC submissions (user-service / compliance-service)
CREATE TABLE IF NOT EXISTS kyc_submissions (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    user_id UUID NOT NULL REFERENCES users(id),
    target_level SMALLINT NOT NULL CHECK (target_level BETWEEN 1 AND 3),
    full_name VARCHAR(200),
    id_type VARCHAR(20) CHECK (id_type IN ('passport', 'id_card', 'driver_license')),
    id_number VARCHAR(50),
    date_of_birth DATE,
    id_front_url VARCHAR(500),
    id_back_url VARCHAR(500),
    selfie_url VARCHAR(500),
    address TEXT,
    annual_income NUMERIC(15,2),
    net_worth NUMERIC(15,2),
    status VARCHAR(20) NOT NULL DEFAULT 'pending' CHECK (status IN ('pending', 'approved', 'rejected')),
    reject_reason VARCHAR(500),
    reviewed_by UUID REFERENCES users(id),
    reviewed_at TIMESTAMPTZ,
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE INDEX idx_kyc_user_id ON kyc_submissions(user_id);
CREATE INDEX idx_kyc_status ON kyc_submissions(status);
