-- name: GetCashiersByBranch :many
SELECT users.*
FROM branch_cashiers
    JOIN users ON branch_cashiers.user_id = users.id
    JOIN branches ON branches.id = branch_id
WHERE branch_cashiers.branch_id = $1;
-- name: GetAllCashiers :many
SELECT users.*,
    branch_id,
    branches.name AS branch_name,
    branches.wallet_id AS branch_wallet,
    branches.location As branch_location
FROM branch_cashiers
    JOIN users ON branch_cashiers.user_id = users.id
    JOIN branches ON branches.id = branch_id
WHERE (
        first_name ILIKE '%' || sqlc.narg('query') || '%'
        OR last_name ILIKE '%' || sqlc.narg('query') || '%'
        OR phone_number ILIKE '%' || sqlc.narg('query') || '%'
        OR sqlc.narg('query') IS NULL
    )
    AND (
        users.created_at > sqlc.narg('created_before')
        OR sqlc.narg('created_before') IS NULL
    )
    AND (
        users.created_at < sqlc.narg('created_after')
        OR sqlc.narg('created_after') IS NULL
    );
-- name: GetCashierByID :one
SELECT users.*,
    branch_id,
    branches.name AS branch_name,
    branches.wallet_id AS branch_wallet,
    branches.location As branch_location
FROM branch_cashiers
    JOIN users ON branch_cashiers.user_id = users.id
    JOIN branches ON branches.id = branch_id
WHERE users.id = $1;