CREATE TABLE users (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    appwrite_id VARCHAR(255) UNIQUE NOT NULL,
    email VARCHAR(255) UNIQUE NOT NULL,
    full_name VARCHAR(255),
    role VARCHAR(20) DEFAULT 'user' CHECK (role IN ('admin', 'manager', 'user')),
    is_active BOOLEAN DEFAULT true,
    last_login TIMESTAMP WITH TIME ZONE,
    created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE user_security_configs (
    user_id UUID REFERENCES users(id) ON DELETE CASCADE,
    master_key_hint VARCHAR(100),
    encryption_version INT DEFAULT 1,
    PRIMARY KEY (user_id)
);
