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

package lrdb

import (
	"context"
	"time"

	"github.com/google/uuid"
	"github.com/jackc/pgx/v5/pgtype"
)

const listServiceNames = `-- name: ListServiceNames :many
SELECT DISTINCT service_name::text
FROM lrdb_service_identifiers
WHERE organization_id = $1::uuid
ORDER BY service_name
`

func (q *Queries) ListServiceNames(ctx context.Context, organizationID uuid.UUID) ([]string, error) {
	rows, err := q.db.Query(ctx, listServiceNames, organizationID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []string
	for rows.Next() {
		var service_name string
		if err := rows.Scan(&service_name); err != nil {
			return nil, err
		}
		items = append(items, service_name)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const upsertServiceIdentifier = `-- name: UpsertServiceIdentifier :one
INSERT INTO lrdb_service_identifiers
  (organization_id, service_name, cluster_name, namespace)
  VALUES ($1, $2, $3, $4)
  ON CONFLICT (organization_id, service_name, cluster_name, namespace)
  DO UPDATE SET updated_at = now()
  RETURNING id, created_at
`

type UpsertServiceIdentifierParams struct {
	OrganizationID pgtype.UUID `json:"organization_id"`
	ServiceName    *string     `json:"service_name"`
	ClusterName    *string     `json:"cluster_name"`
	Namespace      *string     `json:"namespace"`
}

type UpsertServiceIdentifierRow struct {
	ID        uuid.UUID `json:"id"`
	CreatedAt time.Time `json:"created_at"`
}

func (q *Queries) UpsertServiceIdentifier(ctx context.Context, arg UpsertServiceIdentifierParams) (UpsertServiceIdentifierRow, error) {
	row := q.db.QueryRow(ctx, upsertServiceIdentifier,
		arg.OrganizationID,
		arg.ServiceName,
		arg.ClusterName,
		arg.Namespace,
	)
	var i UpsertServiceIdentifierRow
	err := row.Scan(&i.ID, &i.CreatedAt)
	return i, err
}
