-- name: CreateUser :one

INSERT INTO users (first_name, last_name, email, phone_number, role, password, email_verified, phone_verified, created_at, updated_at)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
RETURNING id, first_name, last_name, email, phone_number, role, email_verified, phone_verified, created_at, updated_at;

-- name: GetUserByID :one
SELECT *
FROM users
WHERE id = $1;

-- name: GetAllUsers :many
SELECT id, first_name, last_name, email, phone_number, role, email_verified, phone_verified, created_at, updated_at
FROM users;

-- name: UpdateUser :exec
UPDATE users
SET first_name = $1, last_name = $2, email = $3, phone_number = $4, role = $5, updated_at = $6
WHERE id = $7;

-- name: DeleteUser :exec
DELETE FROM users
WHERE id = $1;

-- name: CheckPhoneEmailExist :one
SELECT 
    EXISTS (SELECT 1 FROM users WHERE users.phone_number = $1 AND users.phone_number IS NOT NULL) AS phone_exists, 
    EXISTS (SELECT 1 FROM users WHERE users.email = $2 AND users.email IS NOT NULL) AS email_exists;
-- name: GetUserByEmail :one
SELECT id, first_name, last_name, email, phone_number, role, email_verified, phone_verified, created_at, updated_at
FROM users
WHERE email = $1;

-- name: GetUserByPhone :one
SELECT id, first_name, last_name, email, phone_number, role, email_verified, phone_verified, created_at, updated_at
FROM users
WHERE phone_number = $1;

-- name: UpdatePassword :exec
UPDATE users
SET password = $1, updated_at = $4
WHERE (email = $2 OR phone_number = $3);