-- name: CreateSysUserLoginLog :exec
INSERT INTO sys_user_login_log (created_at,
                                email,
                                username,
                                user_uuid,
                                is_success,
                                message,
                                referer_url,
                                url,
                                os,
                                ip,
                                browser)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11);

-- name: CountSysUserLoginLogCondition :one
SELECT COUNT(*) FROM sys_user_login_log
WHERE created_at BETWEEN @start_at AND @end_at
    AND (@email::text = '' OR email ILIKE '%' || @email || '%')
    AND (@username::text = '' OR username ILIKE '%' || @username || '%');

-- name: ListSysUserLoginLogCondition :many
SELECT * FROM sys_user_login_log
WHERE created_at BETWEEN @start_at AND @end_at
    AND (@email::text = '' OR email ILIKE '%' || @email || '%')
    AND (@username::text = '' OR username ILIKE '%' || @username || '%')
ORDER BY created_at DESC
OFFSET @skip
LIMIT @size;