// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.27.0
// source: query.sql

package queries

import (
	"context"
	"database/sql"
)

const createEvent = `-- name: CreateEvent :one
INSERT INTO "Events" (
    "CloudId", "Source", "EventTime", "ChainId", "VmId", "VmName", "EventKey", "DatacenterId", "DatacenterName", "ComputeResourceId", "ComputeResourceName", "UserName"
) VALUES(
    ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
)
RETURNING Eid, CloudId, Source, EventTime, ChainId, VmId, EventKey, DatacenterName, ComputeResourceName, UserName, Processed, DatacenterId, ComputeResourceId, VmName, EventType
`

type CreateEventParams struct {
	CloudId             string
	Source              string
	EventTime           sql.NullInt64
	ChainId             string
	VmId                sql.NullString
	VmName              sql.NullString
	EventKey            sql.NullString
	DatacenterId        sql.NullString
	DatacenterName      sql.NullString
	ComputeResourceId   sql.NullString
	ComputeResourceName sql.NullString
	UserName            sql.NullString
}

func (q *Queries) CreateEvent(ctx context.Context, arg CreateEventParams) (Events, error) {
	row := q.db.QueryRowContext(ctx, createEvent,
		arg.CloudId,
		arg.Source,
		arg.EventTime,
		arg.ChainId,
		arg.VmId,
		arg.VmName,
		arg.EventKey,
		arg.DatacenterId,
		arg.DatacenterName,
		arg.ComputeResourceId,
		arg.ComputeResourceName,
		arg.UserName,
	)
	var i Events
	err := row.Scan(
		&i.Eid,
		&i.CloudId,
		&i.Source,
		&i.EventTime,
		&i.ChainId,
		&i.VmId,
		&i.EventKey,
		&i.DatacenterName,
		&i.ComputeResourceName,
		&i.UserName,
		&i.Processed,
		&i.DatacenterId,
		&i.ComputeResourceId,
		&i.VmName,
		&i.EventType,
	)
	return i, err
}

const createInventory = `-- name: CreateInventory :one
INSERT INTO "Inventory" (
    "Name", "Vcenter", "VmId", "EventKey", "CloudId", "CreationTime", "ResourcePool", "VmType", "IsTemplate", "Datacenter", "Cluster", "Folder", "ProvisionedDisk", "InitialVcpus", "InitialRam", "SrmPlaceholder", "PowerState"
) VALUES(
    ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
)
RETURNING Iid, Name, Vcenter, VmId, EventKey, CloudId, CreationTime, DeletionTime, ResourcePool, VmType, Datacenter, Cluster, Folder, ProvisionedDisk, InitialVcpus, InitialRam, SrmPlaceholder, IsTemplate, PowerState
`

type CreateInventoryParams struct {
	Name            string
	Vcenter         string
	VmId            sql.NullString
	EventKey        sql.NullString
	CloudId         sql.NullString
	CreationTime    sql.NullInt64
	ResourcePool    sql.NullString
	VmType          sql.NullString
	IsTemplate      sql.NullInt64
	Datacenter      sql.NullString
	Cluster         sql.NullString
	Folder          sql.NullString
	ProvisionedDisk sql.NullFloat64
	InitialVcpus    sql.NullInt64
	InitialRam      sql.NullInt64
	SrmPlaceholder  sql.NullInt64
	PowerState      sql.NullInt64
}

func (q *Queries) CreateInventory(ctx context.Context, arg CreateInventoryParams) (Inventory, error) {
	row := q.db.QueryRowContext(ctx, createInventory,
		arg.Name,
		arg.Vcenter,
		arg.VmId,
		arg.EventKey,
		arg.CloudId,
		arg.CreationTime,
		arg.ResourcePool,
		arg.VmType,
		arg.IsTemplate,
		arg.Datacenter,
		arg.Cluster,
		arg.Folder,
		arg.ProvisionedDisk,
		arg.InitialVcpus,
		arg.InitialRam,
		arg.SrmPlaceholder,
		arg.PowerState,
	)
	var i Inventory
	err := row.Scan(
		&i.Iid,
		&i.Name,
		&i.Vcenter,
		&i.VmId,
		&i.EventKey,
		&i.CloudId,
		&i.CreationTime,
		&i.DeletionTime,
		&i.ResourcePool,
		&i.VmType,
		&i.Datacenter,
		&i.Cluster,
		&i.Folder,
		&i.ProvisionedDisk,
		&i.InitialVcpus,
		&i.InitialRam,
		&i.SrmPlaceholder,
		&i.IsTemplate,
		&i.PowerState,
	)
	return i, err
}

const createUpdate = `-- name: CreateUpdate :one
INSERT INTO "Updates" (
    "InventoryId", "EventKey", "EventId", "UpdateTime", "UpdateType", "NewVcpus", "NewRam", "NewResourcePool", "NewProvisionedDisk"
) VALUES(
    ?, ?, ?, ?, ?, ?, ?, ?, ?
)
RETURNING Uid, InventoryId, UpdateTime, UpdateType, NewVcpus, NewRam, NewResourcePool, EventKey, EventId, NewProvisionedDisk
`

type CreateUpdateParams struct {
	InventoryId        sql.NullInt64
	EventKey           sql.NullString
	EventId            sql.NullString
	UpdateTime         sql.NullInt64
	UpdateType         string
	NewVcpus           sql.NullInt64
	NewRam             sql.NullInt64
	NewResourcePool    sql.NullString
	NewProvisionedDisk sql.NullFloat64
}

func (q *Queries) CreateUpdate(ctx context.Context, arg CreateUpdateParams) (Updates, error) {
	row := q.db.QueryRowContext(ctx, createUpdate,
		arg.InventoryId,
		arg.EventKey,
		arg.EventId,
		arg.UpdateTime,
		arg.UpdateType,
		arg.NewVcpus,
		arg.NewRam,
		arg.NewResourcePool,
		arg.NewProvisionedDisk,
	)
	var i Updates
	err := row.Scan(
		&i.Uid,
		&i.InventoryId,
		&i.UpdateTime,
		&i.UpdateType,
		&i.NewVcpus,
		&i.NewRam,
		&i.NewResourcePool,
		&i.EventKey,
		&i.EventId,
		&i.NewProvisionedDisk,
	)
	return i, err
}

const getInventoryByName = `-- name: GetInventoryByName :many
SELECT Iid, Name, Vcenter, VmId, EventKey, CloudId, CreationTime, DeletionTime, ResourcePool, VmType, Datacenter, Cluster, Folder, ProvisionedDisk, InitialVcpus, InitialRam, SrmPlaceholder, IsTemplate, PowerState FROM "Inventory"
WHERE "Name" = ?
`

func (q *Queries) GetInventoryByName(ctx context.Context, name string) ([]Inventory, error) {
	rows, err := q.db.QueryContext(ctx, getInventoryByName, name)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []Inventory
	for rows.Next() {
		var i Inventory
		if err := rows.Scan(
			&i.Iid,
			&i.Name,
			&i.Vcenter,
			&i.VmId,
			&i.EventKey,
			&i.CloudId,
			&i.CreationTime,
			&i.DeletionTime,
			&i.ResourcePool,
			&i.VmType,
			&i.Datacenter,
			&i.Cluster,
			&i.Folder,
			&i.ProvisionedDisk,
			&i.InitialVcpus,
			&i.InitialRam,
			&i.SrmPlaceholder,
			&i.IsTemplate,
			&i.PowerState,
		); 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 getInventoryEventId = `-- name: GetInventoryEventId :one
SELECT Iid, Name, Vcenter, VmId, EventKey, CloudId, CreationTime, DeletionTime, ResourcePool, VmType, Datacenter, Cluster, Folder, ProvisionedDisk, InitialVcpus, InitialRam, SrmPlaceholder, IsTemplate, PowerState FROM "Inventory"
WHERE "CloudId" = ? LIMIT 1
`

func (q *Queries) GetInventoryEventId(ctx context.Context, cloudid sql.NullString) (Inventory, error) {
	row := q.db.QueryRowContext(ctx, getInventoryEventId, cloudid)
	var i Inventory
	err := row.Scan(
		&i.Iid,
		&i.Name,
		&i.Vcenter,
		&i.VmId,
		&i.EventKey,
		&i.CloudId,
		&i.CreationTime,
		&i.DeletionTime,
		&i.ResourcePool,
		&i.VmType,
		&i.Datacenter,
		&i.Cluster,
		&i.Folder,
		&i.ProvisionedDisk,
		&i.InitialVcpus,
		&i.InitialRam,
		&i.SrmPlaceholder,
		&i.IsTemplate,
		&i.PowerState,
	)
	return i, err
}

const getInventoryVmId = `-- name: GetInventoryVmId :one
SELECT Iid, Name, Vcenter, VmId, EventKey, CloudId, CreationTime, DeletionTime, ResourcePool, VmType, Datacenter, Cluster, Folder, ProvisionedDisk, InitialVcpus, InitialRam, SrmPlaceholder, IsTemplate, PowerState FROM "Inventory"
WHERE "VmId" = ?1  AND "Datacenter" = ?2
`

type GetInventoryVmIdParams struct {
	VmId           sql.NullString
	DatacenterName sql.NullString
}

func (q *Queries) GetInventoryVmId(ctx context.Context, arg GetInventoryVmIdParams) (Inventory, error) {
	row := q.db.QueryRowContext(ctx, getInventoryVmId, arg.VmId, arg.DatacenterName)
	var i Inventory
	err := row.Scan(
		&i.Iid,
		&i.Name,
		&i.Vcenter,
		&i.VmId,
		&i.EventKey,
		&i.CloudId,
		&i.CreationTime,
		&i.DeletionTime,
		&i.ResourcePool,
		&i.VmType,
		&i.Datacenter,
		&i.Cluster,
		&i.Folder,
		&i.ProvisionedDisk,
		&i.InitialVcpus,
		&i.InitialRam,
		&i.SrmPlaceholder,
		&i.IsTemplate,
		&i.PowerState,
	)
	return i, err
}

const inventoryMarkDeleted = `-- name: InventoryMarkDeleted :exec
UPDATE "Inventory"
SET "DeletionTime" = ?1
WHERE "VmId" = ?2 AND "Datacenter" = ?3
`

type InventoryMarkDeletedParams struct {
	DeletionTime   sql.NullInt64
	VmId           sql.NullString
	DatacenterName sql.NullString
}

func (q *Queries) InventoryMarkDeleted(ctx context.Context, arg InventoryMarkDeletedParams) error {
	_, err := q.db.ExecContext(ctx, inventoryMarkDeleted, arg.DeletionTime, arg.VmId, arg.DatacenterName)
	return err
}

const listEvents = `-- name: ListEvents :many
SELECT Eid, CloudId, Source, EventTime, ChainId, VmId, EventKey, DatacenterName, ComputeResourceName, UserName, Processed, DatacenterId, ComputeResourceId, VmName, EventType FROM "Events"
ORDER BY "EventTime"
`

func (q *Queries) ListEvents(ctx context.Context) ([]Events, error) {
	rows, err := q.db.QueryContext(ctx, listEvents)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []Events
	for rows.Next() {
		var i Events
		if err := rows.Scan(
			&i.Eid,
			&i.CloudId,
			&i.Source,
			&i.EventTime,
			&i.ChainId,
			&i.VmId,
			&i.EventKey,
			&i.DatacenterName,
			&i.ComputeResourceName,
			&i.UserName,
			&i.Processed,
			&i.DatacenterId,
			&i.ComputeResourceId,
			&i.VmName,
			&i.EventType,
		); 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 listInventory = `-- name: ListInventory :many
SELECT Iid, Name, Vcenter, VmId, EventKey, CloudId, CreationTime, DeletionTime, ResourcePool, VmType, Datacenter, Cluster, Folder, ProvisionedDisk, InitialVcpus, InitialRam, SrmPlaceholder, IsTemplate, PowerState FROM "Inventory"
ORDER BY "Name"
`

func (q *Queries) ListInventory(ctx context.Context) ([]Inventory, error) {
	rows, err := q.db.QueryContext(ctx, listInventory)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []Inventory
	for rows.Next() {
		var i Inventory
		if err := rows.Scan(
			&i.Iid,
			&i.Name,
			&i.Vcenter,
			&i.VmId,
			&i.EventKey,
			&i.CloudId,
			&i.CreationTime,
			&i.DeletionTime,
			&i.ResourcePool,
			&i.VmType,
			&i.Datacenter,
			&i.Cluster,
			&i.Folder,
			&i.ProvisionedDisk,
			&i.InitialVcpus,
			&i.InitialRam,
			&i.SrmPlaceholder,
			&i.IsTemplate,
			&i.PowerState,
		); 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 listUnprocessedEvents = `-- name: ListUnprocessedEvents :many
SELECT Eid, CloudId, Source, EventTime, ChainId, VmId, EventKey, DatacenterName, ComputeResourceName, UserName, Processed, DatacenterId, ComputeResourceId, VmName, EventType FROM "Events"
WHERE "Processed" = 0
AND "EventTime" > ?1
ORDER BY "EventTime"
`

func (q *Queries) ListUnprocessedEvents(ctx context.Context, eventtime sql.NullInt64) ([]Events, error) {
	rows, err := q.db.QueryContext(ctx, listUnprocessedEvents, eventtime)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []Events
	for rows.Next() {
		var i Events
		if err := rows.Scan(
			&i.Eid,
			&i.CloudId,
			&i.Source,
			&i.EventTime,
			&i.ChainId,
			&i.VmId,
			&i.EventKey,
			&i.DatacenterName,
			&i.ComputeResourceName,
			&i.UserName,
			&i.Processed,
			&i.DatacenterId,
			&i.ComputeResourceId,
			&i.VmName,
			&i.EventType,
		); 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 updateEventsProcessed = `-- name: UpdateEventsProcessed :exec
UPDATE "Events"
SET "Processed" = 1
WHERE "Eid" = ?1
`

func (q *Queries) UpdateEventsProcessed(ctx context.Context, eid int64) error {
	_, err := q.db.ExecContext(ctx, updateEventsProcessed, eid)
	return err
}
