-- Users
CREATE TABLE IF NOT EXISTS public.users (
    id UUID DEFAULT gen_random_uuid () NOT NULL,
    username TEXT NOT NULL,
    email TEXT NOT NULL,
    "isAdmin" boolean DEFAULT FALSE NOT NULL,
    "isBlocked" boolean DEFAULT FALSE NOT NULL,
    PASSWORD TEXT NOT NULL,
    nome TEXT NOT NULL,
    cognome TEXT NOT NULL,
    created_at TIMESTAMP WITHOUT TIME ZONE DEFAULT now() NOT NULL,
    reset_password_token TEXT,
    reset_password_expires TIMESTAMP WITHOUT TIME ZONE,
    telefono TEXT NOT NULL,
    "isAdminMade" boolean DEFAULT FALSE,
    "isVerified" boolean DEFAULT FALSE NOT NULL,
    "verificationToken" TEXT,
    "verificationTokenExpires" TIMESTAMP WITHOUT TIME ZONE,
    salt TEXT NOT NULL
);
-- Primary Key
DO $$ BEGIN
ALTER TABLE public.users
ADD CONSTRAINT users_pkey PRIMARY KEY (id);
    EXCEPTION
        WHEN invalid_table_definition THEN 
            RAISE NOTICE 'Primary key already exists. Ignoring...';
END $$;
-- Unique Email
DO $$ BEGIN IF NOT EXISTS (
    SELECT 1
    FROM pg_constraint
    WHERE conname = 'users_email_key'
    ) THEN
        ALTER TABLE public.users
        ADD CONSTRAINT users_email_key UNIQUE (email);
    END IF;
END $$;