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

package configdb

import (
	"context"

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

const getStorageProfileByCollectorNameUncached = `-- name: GetStorageProfileByCollectorNameUncached :one
SELECT
  sp.cloud_provider AS cloud_provider,
  sp.region AS region,
  sp.role AS role,
  sp.bucket AS bucket,
  c.instance_num::SMALLINT AS instance_num,
  c.organization_id::UUID AS organization_id,
  c.external_id::TEXT AS external_id
FROM
  c_storage_profiles sp
  LEFT OUTER JOIN c_collectors c ON c.storage_profile_id = sp.id
WHERE
  c.deleted_at IS NULL
  AND c.organization_id = $1
  AND c.external_id = 'default'
  AND EXISTS (SELECT 1 FROM organizations o WHERE o.id = c.organization_id AND o.enabled = true)
`

type GetStorageProfileByCollectorNameRow struct {
	CloudProvider  string    `json:"cloud_provider"`
	Region         string    `json:"region"`
	Role           *string   `json:"role"`
	Bucket         string    `json:"bucket"`
	InstanceNum    int16     `json:"instance_num"`
	OrganizationID uuid.UUID `json:"organization_id"`
	ExternalID     string    `json:"external_id"`
}

func (q *Queries) GetStorageProfileByCollectorNameUncached(ctx context.Context, organizationID pgtype.UUID) (GetStorageProfileByCollectorNameRow, error) {
	row := q.db.QueryRow(ctx, getStorageProfileByCollectorNameUncached, organizationID)
	var i GetStorageProfileByCollectorNameRow
	err := row.Scan(
		&i.CloudProvider,
		&i.Region,
		&i.Role,
		&i.Bucket,
		&i.InstanceNum,
		&i.OrganizationID,
		&i.ExternalID,
	)
	return i, err
}

const getStorageProfileUncached = `-- name: GetStorageProfileUncached :one
SELECT
  sp.cloud_provider AS cloud_provider,
  sp.region AS region,
  sp.role AS role,
  sp.bucket AS bucket,
  c.instance_num::SMALLINT AS instance_num,
  c.organization_id::UUID AS organization_id,
  c.external_id::TEXT AS external_id
FROM
  c_storage_profiles sp
  LEFT OUTER JOIN c_collectors c ON c.storage_profile_id = sp.id
WHERE
  c.deleted_at IS NULL
  AND c.organization_id = $1
  AND c.instance_num = $2
  AND EXISTS (SELECT 1 FROM organizations o WHERE o.id = c.organization_id AND o.enabled = true)
`

type GetStorageProfileParams struct {
	OrganizationID pgtype.UUID `json:"organization_id"`
	InstanceNum    int16       `json:"instance_num"`
}

type GetStorageProfileRow struct {
	CloudProvider  string    `json:"cloud_provider"`
	Region         string    `json:"region"`
	Role           *string   `json:"role"`
	Bucket         string    `json:"bucket"`
	InstanceNum    int16     `json:"instance_num"`
	OrganizationID uuid.UUID `json:"organization_id"`
	ExternalID     string    `json:"external_id"`
}

func (q *Queries) GetStorageProfileUncached(ctx context.Context, arg GetStorageProfileParams) (GetStorageProfileRow, error) {
	row := q.db.QueryRow(ctx, getStorageProfileUncached, arg.OrganizationID, arg.InstanceNum)
	var i GetStorageProfileRow
	err := row.Scan(
		&i.CloudProvider,
		&i.Region,
		&i.Role,
		&i.Bucket,
		&i.InstanceNum,
		&i.OrganizationID,
		&i.ExternalID,
	)
	return i, err
}

const getStorageProfilesByBucketNameUncached = `-- name: GetStorageProfilesByBucketNameUncached :many
SELECT
  sp.cloud_provider AS cloud_provider,
  sp.region AS region,
  sp.role AS role,
  sp.bucket AS bucket,
  c.instance_num::SMALLINT AS instance_num,
  c.organization_id::UUID AS organization_id,
  c.external_id::TEXT AS external_id
FROM
  c_storage_profiles sp
  LEFT OUTER JOIN c_collectors c ON c.storage_profile_id = sp.id
WHERE
  c.deleted_at IS NULL
  AND sp.bucket = $1
  AND EXISTS (SELECT 1 FROM organizations o WHERE o.id = c.organization_id AND o.enabled = true)
`

type GetStorageProfilesByBucketNameRow struct {
	CloudProvider  string    `json:"cloud_provider"`
	Region         string    `json:"region"`
	Role           *string   `json:"role"`
	Bucket         string    `json:"bucket"`
	InstanceNum    int16     `json:"instance_num"`
	OrganizationID uuid.UUID `json:"organization_id"`
	ExternalID     string    `json:"external_id"`
}

func (q *Queries) GetStorageProfilesByBucketNameUncached(ctx context.Context, bucketName string) ([]GetStorageProfilesByBucketNameRow, error) {
	rows, err := q.db.Query(ctx, getStorageProfilesByBucketNameUncached, bucketName)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []GetStorageProfilesByBucketNameRow
	for rows.Next() {
		var i GetStorageProfilesByBucketNameRow
		if err := rows.Scan(
			&i.CloudProvider,
			&i.Region,
			&i.Role,
			&i.Bucket,
			&i.InstanceNum,
			&i.OrganizationID,
			&i.ExternalID,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}
