// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.25.0
// source: static_addresses.sql

package sqlc

import (
	"context"
)

const allStaticAddresses = `-- name: AllStaticAddresses :many
SELECT id, client_pubkey, server_pubkey, expiry, client_key_family, client_key_index, pkscript, protocol_version, initiation_height FROM static_addresses
`

func (q *Queries) AllStaticAddresses(ctx context.Context) ([]StaticAddress, error) {
	rows, err := q.db.QueryContext(ctx, allStaticAddresses)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []StaticAddress
	for rows.Next() {
		var i StaticAddress
		if err := rows.Scan(
			&i.ID,
			&i.ClientPubkey,
			&i.ServerPubkey,
			&i.Expiry,
			&i.ClientKeyFamily,
			&i.ClientKeyIndex,
			&i.Pkscript,
			&i.ProtocolVersion,
			&i.InitiationHeight,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Close(); err != nil {
		return nil, err
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const createStaticAddress = `-- name: CreateStaticAddress :exec
INSERT INTO static_addresses (
    client_pubkey,
    server_pubkey,
    expiry,
    client_key_family,
    client_key_index,
    pkscript,
    protocol_version,
    initiation_height
) VALUES (
             $1,
             $2,
             $3,
             $4,
             $5,
             $6,
             $7,
             $8
         )
`

type CreateStaticAddressParams struct {
	ClientPubkey     []byte
	ServerPubkey     []byte
	Expiry           int32
	ClientKeyFamily  int32
	ClientKeyIndex   int32
	Pkscript         []byte
	ProtocolVersion  int32
	InitiationHeight int32
}

func (q *Queries) CreateStaticAddress(ctx context.Context, arg CreateStaticAddressParams) error {
	_, err := q.db.ExecContext(ctx, createStaticAddress,
		arg.ClientPubkey,
		arg.ServerPubkey,
		arg.Expiry,
		arg.ClientKeyFamily,
		arg.ClientKeyIndex,
		arg.Pkscript,
		arg.ProtocolVersion,
		arg.InitiationHeight,
	)
	return err
}

const getStaticAddress = `-- name: GetStaticAddress :one
SELECT id, client_pubkey, server_pubkey, expiry, client_key_family, client_key_index, pkscript, protocol_version, initiation_height FROM static_addresses
WHERE pkscript=$1
`

func (q *Queries) GetStaticAddress(ctx context.Context, pkscript []byte) (StaticAddress, error) {
	row := q.db.QueryRowContext(ctx, getStaticAddress, pkscript)
	var i StaticAddress
	err := row.Scan(
		&i.ID,
		&i.ClientPubkey,
		&i.ServerPubkey,
		&i.Expiry,
		&i.ClientKeyFamily,
		&i.ClientKeyIndex,
		&i.Pkscript,
		&i.ProtocolVersion,
		&i.InitiationHeight,
	)
	return i, err
}
