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

package sql

import (
	"context"
	"strings"
)

const createHost = `-- name: CreateHost :exec
INSERT INTO hosts (ID, MAC, Hostname, OS, Platform, KernelVersion, KernelArch, CPUPhysicalID, CPUVendorID, CPUFamily, CPUCount, MemTotal)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
`

type CreateHostParams struct {
	ID            string
	Mac           string
	Hostname      string
	Os            string
	Platform      string
	Kernelversion string
	Kernelarch    string
	Cpuphysicalid string
	Cpuvendorid   string
	Cpufamily     string
	Cpucount      int64
	Memtotal      int64
}

func (q *Queries) CreateHost(ctx context.Context, arg CreateHostParams) error {
	_, err := q.db.ExecContext(ctx, createHost,
		arg.ID,
		arg.Mac,
		arg.Hostname,
		arg.Os,
		arg.Platform,
		arg.Kernelversion,
		arg.Kernelarch,
		arg.Cpuphysicalid,
		arg.Cpuvendorid,
		arg.Cpufamily,
		arg.Cpucount,
		arg.Memtotal,
	)
	return err
}

const deleteHost = `-- name: DeleteHost :exec
DELETE FROM hosts WHERE ID = ?
`

func (q *Queries) DeleteHost(ctx context.Context, id string) error {
	_, err := q.db.ExecContext(ctx, deleteHost, id)
	return err
}

const listHosts = `-- name: ListHosts :many
SELECT id, mac, hostname, os, platform, kernelversion, kernelarch, cpuphysicalid, cpuvendorid, cpufamily, cpucount, memtotal FROM hosts
`

func (q *Queries) ListHosts(ctx context.Context) ([]Host, error) {
	rows, err := q.db.QueryContext(ctx, listHosts)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []Host
	for rows.Next() {
		var i Host
		if err := rows.Scan(
			&i.ID,
			&i.Mac,
			&i.Hostname,
			&i.Os,
			&i.Platform,
			&i.Kernelversion,
			&i.Kernelarch,
			&i.Cpuphysicalid,
			&i.Cpuvendorid,
			&i.Cpufamily,
			&i.Cpucount,
			&i.Memtotal,
		); 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 listHostsByIDs = `-- name: ListHostsByIDs :many
SELECT id, mac, hostname, os, platform, kernelversion, kernelarch, cpuphysicalid, cpuvendorid, cpufamily, cpucount, memtotal FROM hosts WHERE ID in (/*SLICE:ids*/?)
`

func (q *Queries) ListHostsByIDs(ctx context.Context, ids []string) ([]Host, error) {
	query := listHostsByIDs
	var queryParams []interface{}
	if len(ids) > 0 {
		for _, v := range ids {
			queryParams = append(queryParams, v)
		}
		query = strings.Replace(query, "/*SLICE:ids*/?", strings.Repeat(",?", len(ids))[1:], 1)
	} else {
		query = strings.Replace(query, "/*SLICE:ids*/?", "NULL", 1)
	}
	rows, err := q.db.QueryContext(ctx, query, queryParams...)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []Host
	for rows.Next() {
		var i Host
		if err := rows.Scan(
			&i.ID,
			&i.Mac,
			&i.Hostname,
			&i.Os,
			&i.Platform,
			&i.Kernelversion,
			&i.Kernelarch,
			&i.Cpuphysicalid,
			&i.Cpuvendorid,
			&i.Cpufamily,
			&i.Cpucount,
			&i.Memtotal,
		); 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 updateHost = `-- name: UpdateHost :exec
UPDATE hosts SET
    MAC = ?,
    Hostname = ?,
    OS = ?,
    Platform = ?,
    KernelVersion = ?,
    KernelArch = ?,
    CPUPhysicalID = ?,
    CPUVendorID = ?,
    CPUFamily = ?,
    CPUCount = ?,
    MemTotal = ?
WHERE ID = ?
`

type UpdateHostParams struct {
	Mac           string
	Hostname      string
	Os            string
	Platform      string
	Kernelversion string
	Kernelarch    string
	Cpuphysicalid string
	Cpuvendorid   string
	Cpufamily     string
	Cpucount      int64
	Memtotal      int64
	ID            string
}

func (q *Queries) UpdateHost(ctx context.Context, arg UpdateHostParams) error {
	_, err := q.db.ExecContext(ctx, updateHost,
		arg.Mac,
		arg.Hostname,
		arg.Os,
		arg.Platform,
		arg.Kernelversion,
		arg.Kernelarch,
		arg.Cpuphysicalid,
		arg.Cpuvendorid,
		arg.Cpufamily,
		arg.Cpucount,
		arg.Memtotal,
		arg.ID,
	)
	return err
}
