// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.26.0
// source: client.sql

package db

import (
	"context"

	"github.com/jackc/pgx/v5/pgconn"
)

const createClient = `-- name: CreateClient :one
INSERT INTO clients (
  id, created_at, name, description, website, redirect_uris, secret_hash, user_id
) VALUES (
  $1, $2, $3, $4, $5, $6, $7, $8
) RETURNING id, created_at, name, description, website, redirect_uris, secret_hash, user_id
`

type CreateClientParams struct {
	ID           string
	CreatedAt    int64
	Name         string
	Description  string
	Website      string
	RedirectUris []byte
	SecretHash   []byte
	UserID       string
}

func (q *Queries) CreateClient(ctx context.Context, arg CreateClientParams) (Client, error) {
	row := q.db.QueryRow(ctx, createClient,
		arg.ID,
		arg.CreatedAt,
		arg.Name,
		arg.Description,
		arg.Website,
		arg.RedirectUris,
		arg.SecretHash,
		arg.UserID,
	)
	var i Client
	err := row.Scan(
		&i.ID,
		&i.CreatedAt,
		&i.Name,
		&i.Description,
		&i.Website,
		&i.RedirectUris,
		&i.SecretHash,
		&i.UserID,
	)
	return i, err
}

const deleteClient = `-- name: DeleteClient :execresult
DELETE FROM clients WHERE user_id = $1 AND id = $2
`

type DeleteClientParams struct {
	UserID string
	ID     string
}

func (q *Queries) DeleteClient(ctx context.Context, arg DeleteClientParams) (pgconn.CommandTag, error) {
	return q.db.Exec(ctx, deleteClient, arg.UserID, arg.ID)
}

const findClient = `-- name: FindClient :one
SELECT id, created_at, name, description, website, redirect_uris, secret_hash, user_id FROM clients WHERE id = $1
`

func (q *Queries) FindClient(ctx context.Context, id string) (Client, error) {
	row := q.db.QueryRow(ctx, findClient, id)
	var i Client
	err := row.Scan(
		&i.ID,
		&i.CreatedAt,
		&i.Name,
		&i.Description,
		&i.Website,
		&i.RedirectUris,
		&i.SecretHash,
		&i.UserID,
	)
	return i, err
}

const findClientByUser = `-- name: FindClientByUser :many
SELECT id, created_at, name, description, website, redirect_uris, secret_hash, user_id FROM clients WHERE user_id = $1
`

func (q *Queries) FindClientByUser(ctx context.Context, userID string) ([]Client, error) {
	rows, err := q.db.Query(ctx, findClientByUser, userID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []Client
	for rows.Next() {
		var i Client
		if err := rows.Scan(
			&i.ID,
			&i.CreatedAt,
			&i.Name,
			&i.Description,
			&i.Website,
			&i.RedirectUris,
			&i.SecretHash,
			&i.UserID,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const findClientByUserAndID = `-- name: FindClientByUserAndID :one
SELECT id, created_at, name, description, website, redirect_uris, secret_hash, user_id FROM clients WHERE user_id = $1 AND id = $2
`

type FindClientByUserAndIDParams struct {
	UserID string
	ID     string
}

func (q *Queries) FindClientByUserAndID(ctx context.Context, arg FindClientByUserAndIDParams) (Client, error) {
	row := q.db.QueryRow(ctx, findClientByUserAndID, arg.UserID, arg.ID)
	var i Client
	err := row.Scan(
		&i.ID,
		&i.CreatedAt,
		&i.Name,
		&i.Description,
		&i.Website,
		&i.RedirectUris,
		&i.SecretHash,
		&i.UserID,
	)
	return i, err
}

const updateClient = `-- name: UpdateClient :one
UPDATE clients SET
  name = $1, description = $2, website = $3, redirect_uris = $4
WHERE user_id = $5 AND id = $6
RETURNING id, created_at, name, description, website, redirect_uris, secret_hash, user_id
`

type UpdateClientParams struct {
	Name         string
	Description  string
	Website      string
	RedirectUris []byte
	UserID       string
	ID           string
}

func (q *Queries) UpdateClient(ctx context.Context, arg UpdateClientParams) (Client, error) {
	row := q.db.QueryRow(ctx, updateClient,
		arg.Name,
		arg.Description,
		arg.Website,
		arg.RedirectUris,
		arg.UserID,
		arg.ID,
	)
	var i Client
	err := row.Scan(
		&i.ID,
		&i.CreatedAt,
		&i.Name,
		&i.Description,
		&i.Website,
		&i.RedirectUris,
		&i.SecretHash,
		&i.UserID,
	)
	return i, err
}

const updateClientSecret = `-- name: UpdateClientSecret :execresult
UPDATE clients SET secret_hash = $1 WHERE user_id = $2 AND id = $3
`

type UpdateClientSecretParams struct {
	SecretHash []byte
	UserID     string
	ID         string
}

func (q *Queries) UpdateClientSecret(ctx context.Context, arg UpdateClientSecretParams) (pgconn.CommandTag, error) {
	return q.db.Exec(ctx, updateClientSecret, arg.SecretHash, arg.UserID, arg.ID)
}
