CREATE TYPE role AS ENUM ('USER', 'MODERATOR', 'ADMIN');
CREATE TYPE spotlight_type AS ENUM ('SPONSOR', 'WEEKLY_CODE');

CREATE TABLE IF NOT EXISTS spotlight (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    type spotlight_type NOT NULL,
    title VARCHAR(255) NOT NULL,
    code_body TEXT,
    link TEXT,
    is_active BOOLEAN NOT NULL DEFAULT TRUE
);

CREATE TABLE IF NOT EXISTS audit_logs (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    actor_id UUID REFERENCES users(id) ON DELETE SET NULL,
    action VARCHAR(120) NOT NULL,
    target VARCHAR(255),
    description TEXT,
    created_at TIMESTAMP NOT NULL DEFAULT NOW()
);

INSERT INTO spotlight (type, title, code_body, link, is_active)
SELECT 'WEEKLY_CODE', 'Haftanın Kodu', 'if ($user["role"] !== "ADMIN") { http_response_code(403); }', NULL, TRUE
WHERE NOT EXISTS (SELECT 1 FROM spotlight);
