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

package db

import (
	"context"
)

const getAccount = `-- name: GetAccount :one
SELECT user_id, match_key, display_name, avatar_url, roles, provider, created_at, last_login_at
FROM accounts
WHERE user_id = ?
`

func (q *Queries) GetAccount(ctx context.Context, userID string) (Account, error) {
	row := q.db.QueryRowContext(ctx, getAccount, userID)
	var i Account
	err := row.Scan(
		&i.UserID,
		&i.MatchKey,
		&i.DisplayName,
		&i.AvatarUrl,
		&i.Roles,
		&i.Provider,
		&i.CreatedAt,
		&i.LastLoginAt,
	)
	return i, err
}

const upsertAccount = `-- name: UpsertAccount :exec

INSERT INTO accounts (user_id, match_key, display_name, avatar_url, roles, provider, created_at, last_login_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT(user_id) DO UPDATE SET
    match_key = excluded.match_key,
    display_name = excluded.display_name,
    avatar_url = excluded.avatar_url,
    roles = excluded.roles,
    provider = excluded.provider,
    last_login_at = excluded.last_login_at
`

type UpsertAccountParams struct {
	UserID      string `json:"user_id"`
	MatchKey    string `json:"match_key"`
	DisplayName string `json:"display_name"`
	AvatarUrl   string `json:"avatar_url"`
	Roles       string `json:"roles"`
	Provider    string `json:"provider"`
	CreatedAt   int64  `json:"created_at"`
	LastLoginAt int64  `json:"last_login_at"`
}

// accounts: cdrop-side thin account data (AUTH.md 2.1). Keyed on user_id (= OIDC
// sub). No credentials live here; password / second factor stay at the OAuth
// provider. Upserted on every successful OIDC exchange.
//
// ASCII only: sqlc 1.31.x miscomputes byte offsets on multibyte comments and
// corrupts every generated SQL const in the file. Keep this file pure ASCII.
func (q *Queries) UpsertAccount(ctx context.Context, arg UpsertAccountParams) error {
	_, err := q.db.ExecContext(ctx, upsertAccount,
		arg.UserID,
		arg.MatchKey,
		arg.DisplayName,
		arg.AvatarUrl,
		arg.Roles,
		arg.Provider,
		arg.CreatedAt,
		arg.LastLoginAt,
	)
	return err
}
