// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.29.0
// source: interval_settings.sql

package sqlcv1

import (
	"context"

	"github.com/google/uuid"
)

const listIntervalsByOperationId = `-- name: ListIntervalsByOperationId :many
SELECT
    tenant_id, operation_id, interval_nanoseconds
FROM
    v1_operation_interval_settings
WHERE
    operation_id = $1::text
`

func (q *Queries) ListIntervalsByOperationId(ctx context.Context, db DBTX, operationid string) ([]*V1OperationIntervalSettings, error) {
	rows, err := db.Query(ctx, listIntervalsByOperationId, operationid)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []*V1OperationIntervalSettings
	for rows.Next() {
		var i V1OperationIntervalSettings
		if err := rows.Scan(&i.TenantID, &i.OperationID, &i.IntervalNanoseconds); err != nil {
			return nil, err
		}
		items = append(items, &i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const readInterval = `-- name: ReadInterval :one
SELECT
    tenant_id, operation_id, interval_nanoseconds
FROM
    v1_operation_interval_settings
WHERE
    tenant_id = $1::uuid
    AND operation_id = $2::text
LIMIT 1
`

type ReadIntervalParams struct {
	Tenantid    uuid.UUID `json:"tenantid"`
	Operationid string    `json:"operationid"`
}

func (q *Queries) ReadInterval(ctx context.Context, db DBTX, arg ReadIntervalParams) (*V1OperationIntervalSettings, error) {
	row := db.QueryRow(ctx, readInterval, arg.Tenantid, arg.Operationid)
	var i V1OperationIntervalSettings
	err := row.Scan(&i.TenantID, &i.OperationID, &i.IntervalNanoseconds)
	return &i, err
}

const upsertInterval = `-- name: UpsertInterval :one
INSERT INTO v1_operation_interval_settings (
    tenant_id,
    operation_id,
    interval_nanoseconds
) VALUES (
    $1::uuid,
    $2::text,
    $3::bigint
) ON CONFLICT (tenant_id, operation_id) DO UPDATE
SET
    interval_nanoseconds = EXCLUDED.interval_nanoseconds
RETURNING
    tenant_id, operation_id, interval_nanoseconds
`

type UpsertIntervalParams struct {
	Tenantid            uuid.UUID `json:"tenantid"`
	Operationid         string    `json:"operationid"`
	Intervalnanoseconds int64     `json:"intervalnanoseconds"`
}

func (q *Queries) UpsertInterval(ctx context.Context, db DBTX, arg UpsertIntervalParams) (*V1OperationIntervalSettings, error) {
	row := db.QueryRow(ctx, upsertInterval, arg.Tenantid, arg.Operationid, arg.Intervalnanoseconds)
	var i V1OperationIntervalSettings
	err := row.Scan(&i.TenantID, &i.OperationID, &i.IntervalNanoseconds)
	return &i, err
}
