-- name: CreateSysAuditLog :exec
INSERT INTO sys_audit_log (created_at,
                                email,
                                username,
                                user_uuid,
                                start_at,
                                end_at,
                                duration,
                                url,
                                method,
                                parameters,
                                referer_url,
                                os,
                                ip,
                                browser,
                                remark)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15);

-- name: CountSysAuditLogCondition :one
SELECT COUNT(*) FROM sys_audit_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: ListSysAuditLogCondition :many
SELECT * FROM sys_audit_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;