CREATE TABLE users (
    id BIGSERIAL PRIMARY KEY,
    first_name VARCHAR(255) NOT NULL,
    last_name VARCHAR(255) NOT NULL,
    email VARCHAR(255) UNIQUE  ,
    phone_number VARCHAR(20) UNIQUE,
    password BYTEA NOT NULL,
    role VARCHAR(50) NOT NULL,
    email_verified BOOLEAN NOT NULL DEFAULT FALSE,
    phone_verified BOOLEAN NOT NULL DEFAULT FALSE,
    created_at TIMESTAMPTZ  NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMPTZ  NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    suspended_at TIMESTAMPTZ  NULL,  -- this can be NULL if the user is not suspended
    suspended BOOLEAN NOT NULL DEFAULT FALSE,
    CHECK (
        (email IS NOT NULL AND phone_number IS NULL) OR 
        (email IS NULL AND phone_number IS NOT NULL)
    )
);
CREATE TABLE refresh_tokens (
    id BIGSERIAL PRIMARY KEY,
    user_id BIGINT NOT NULL,
    token TEXT NOT NULL UNIQUE,
    expires_at  TIMESTAMPTZ NOT NULL,
    created_at  TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP NOT NULL,
    revoked BOOLEAN DEFAULT FALSE NOT NULL,
    CONSTRAINT unique_token UNIQUE (token)
);
----------------------------------------------seed data-------------------------------------------------------------
-------------------------------------- DO NOT USE IN PRODUCTION-------------------------------------------------

CREATE EXTENSION IF NOT EXISTS pgcrypto;

INSERT INTO users (first_name, last_name, email, phone_number, password, role, created_at, updated_at)
VALUES (
    'John', 
    'Doe', 
    'john.doe@example.com', 
    '1234567890', 
    crypt('password123', gen_salt('bf'))::bytea,  
    'user', 
    CURRENT_TIMESTAMP, 
    CURRENT_TIMESTAMP
);