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

package dbc

import (
	"context"

	"github.com/google/uuid"
)

const cleanupOidcLogins = `-- name: CleanupOidcLogins :exec
delete from keibi.oidc_login
where created_at + interval '10 min' < now()::timestamptz
`

func (q *Queries) CleanupOidcLogins(ctx context.Context) error {
	_, err := q.db.Exec(ctx, cleanupOidcLogins)
	return err
}

const consumeOidcLogin = `-- name: ConsumeOidcLogin :one
delete from keibi.oidc_login
where
	opaque = $1
	and provider = $2
	and tenant = $3
	and created_at + interval '10 min' > now()::timestamptz
returning
	pk, id, opaque, provider, redirect_url, tenant, code, created_at
`

type ConsumeOidcLoginParams struct {
	Opaque   string `json:"opaque"`
	Provider string `json:"provider"`
	Tenant   string `json:"tenant"`
}

func (q *Queries) ConsumeOidcLogin(ctx context.Context, arg ConsumeOidcLoginParams) (OidcLogin, error) {
	row := q.db.QueryRow(ctx, consumeOidcLogin, arg.Opaque, arg.Provider, arg.Tenant)
	var i OidcLogin
	err := row.Scan(
		&i.Pk,
		&i.Id,
		&i.Opaque,
		&i.Provider,
		&i.RedirectUrl,
		&i.Tenant,
		&i.Code,
		&i.CreatedAt,
	)
	return i, err
}

const createOidcLogin = `-- name: CreateOidcLogin :one
insert into keibi.oidc_login(provider, opaque, redirect_url, tenant)
	values ($1, $2, $3, $4)
returning
	pk, id, opaque, provider, redirect_url, tenant, code, created_at
`

type CreateOidcLoginParams struct {
	Provider    string `json:"provider"`
	Opaque      string `json:"opaque"`
	RedirectUrl string `json:"redirectUrl"`
	Tenant      string `json:"tenant"`
}

func (q *Queries) CreateOidcLogin(ctx context.Context, arg CreateOidcLoginParams) (OidcLogin, error) {
	row := q.db.QueryRow(ctx, createOidcLogin,
		arg.Provider,
		arg.Opaque,
		arg.RedirectUrl,
		arg.Tenant,
	)
	var i OidcLogin
	err := row.Scan(
		&i.Pk,
		&i.Id,
		&i.Opaque,
		&i.Provider,
		&i.RedirectUrl,
		&i.Tenant,
		&i.Code,
		&i.CreatedAt,
	)
	return i, err
}

const deleteOidcLoginById = `-- name: DeleteOidcLoginById :exec
delete from keibi.oidc_login
where
	id = $1
`

func (q *Queries) DeleteOidcLoginById(ctx context.Context, id uuid.UUID) error {
	_, err := q.db.Exec(ctx, deleteOidcLoginById, id)
	return err
}

const getOidcLoginByOpaque = `-- name: GetOidcLoginByOpaque :one
select
	pk, id, opaque, provider, redirect_url, tenant, code, created_at
from
	keibi.oidc_login
where
	opaque = $1
	and provider = $2
limit 1
`

type GetOidcLoginByOpaqueParams struct {
	Opaque   string `json:"opaque"`
	Provider string `json:"provider"`
}

func (q *Queries) GetOidcLoginByOpaque(ctx context.Context, arg GetOidcLoginByOpaqueParams) (OidcLogin, error) {
	row := q.db.QueryRow(ctx, getOidcLoginByOpaque, arg.Opaque, arg.Provider)
	var i OidcLogin
	err := row.Scan(
		&i.Pk,
		&i.Id,
		&i.Opaque,
		&i.Provider,
		&i.RedirectUrl,
		&i.Tenant,
		&i.Code,
		&i.CreatedAt,
	)
	return i, err
}

const saveOidcLoginCode = `-- name: SaveOidcLoginCode :exec
update
	keibi.oidc_login
set
	code = $2
where
	id = $1
`

type SaveOidcLoginCodeParams struct {
	Id   uuid.UUID `json:"id"`
	Code *string   `json:"code"`
}

func (q *Queries) SaveOidcLoginCode(ctx context.Context, arg SaveOidcLoginCodeParams) error {
	_, err := q.db.Exec(ctx, saveOidcLoginCode, arg.Id, arg.Code)
	return err
}
