// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.31.1
// source: session_queries.sql

package postgres

import (
	"context"
)

const createSession = `-- name: CreateSession :one
INSERT INTO "sessions" (
    "uuid",
    "username",
    "email",
    "name",
    "provider",
    "totp_pending",
    "oauth_groups",
    "expiry",
    "created_at",
    "oauth_name",
    "oauth_sub"
) VALUES (
    $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11
)
RETURNING uuid, username, email, name, provider, totp_pending, oauth_groups, expiry, created_at, oauth_name, oauth_sub
`

type CreateSessionParams struct {
	UUID        string
	Username    string
	Email       string
	Name        string
	Provider    string
	TotpPending bool
	OAuthGroups string
	Expiry      int64
	CreatedAt   int64
	OAuthName   string
	OAuthSub    string
}

func (q *Queries) CreateSession(ctx context.Context, arg CreateSessionParams) (Session, error) {
	row := q.db.QueryRowContext(ctx, createSession,
		arg.UUID,
		arg.Username,
		arg.Email,
		arg.Name,
		arg.Provider,
		arg.TotpPending,
		arg.OAuthGroups,
		arg.Expiry,
		arg.CreatedAt,
		arg.OAuthName,
		arg.OAuthSub,
	)
	var i Session
	err := row.Scan(
		&i.UUID,
		&i.Username,
		&i.Email,
		&i.Name,
		&i.Provider,
		&i.TotpPending,
		&i.OAuthGroups,
		&i.Expiry,
		&i.CreatedAt,
		&i.OAuthName,
		&i.OAuthSub,
	)
	return i, err
}

const deleteExpiredSessions = `-- name: DeleteExpiredSessions :exec
DELETE FROM "sessions"
WHERE "expiry" < $1
`

func (q *Queries) DeleteExpiredSessions(ctx context.Context, expiry int64) error {
	_, err := q.db.ExecContext(ctx, deleteExpiredSessions, expiry)
	return err
}

const deleteSession = `-- name: DeleteSession :exec
DELETE FROM "sessions"
WHERE "uuid" = $1
`

func (q *Queries) DeleteSession(ctx context.Context, uuid string) error {
	_, err := q.db.ExecContext(ctx, deleteSession, uuid)
	return err
}

const getSession = `-- name: GetSession :one
SELECT uuid, username, email, name, provider, totp_pending, oauth_groups, expiry, created_at, oauth_name, oauth_sub FROM "sessions"
WHERE "uuid" = $1
`

func (q *Queries) GetSession(ctx context.Context, uuid string) (Session, error) {
	row := q.db.QueryRowContext(ctx, getSession, uuid)
	var i Session
	err := row.Scan(
		&i.UUID,
		&i.Username,
		&i.Email,
		&i.Name,
		&i.Provider,
		&i.TotpPending,
		&i.OAuthGroups,
		&i.Expiry,
		&i.CreatedAt,
		&i.OAuthName,
		&i.OAuthSub,
	)
	return i, err
}

const updateSession = `-- name: UpdateSession :one
UPDATE "sessions" SET
    "username"     = $1,
    "email"        = $2,
    "name"         = $3,
    "provider"     = $4,
    "totp_pending" = $5,
    "oauth_groups" = $6,
    "expiry"       = $7,
    "oauth_name"   = $8,
    "oauth_sub"    = $9
WHERE "uuid" = $10
RETURNING uuid, username, email, name, provider, totp_pending, oauth_groups, expiry, created_at, oauth_name, oauth_sub
`

type UpdateSessionParams struct {
	Username    string
	Email       string
	Name        string
	Provider    string
	TotpPending bool
	OAuthGroups string
	Expiry      int64
	OAuthName   string
	OAuthSub    string
	UUID        string
}

func (q *Queries) UpdateSession(ctx context.Context, arg UpdateSessionParams) (Session, error) {
	row := q.db.QueryRowContext(ctx, updateSession,
		arg.Username,
		arg.Email,
		arg.Name,
		arg.Provider,
		arg.TotpPending,
		arg.OAuthGroups,
		arg.Expiry,
		arg.OAuthName,
		arg.OAuthSub,
		arg.UUID,
	)
	var i Session
	err := row.Scan(
		&i.UUID,
		&i.Username,
		&i.Email,
		&i.Name,
		&i.Provider,
		&i.TotpPending,
		&i.OAuthGroups,
		&i.Expiry,
		&i.CreatedAt,
		&i.OAuthName,
		&i.OAuthSub,
	)
	return i, err
}
