// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.25.0
// source: queries.sql

package db

import (
	"context"
)

const deleteGroup = `-- name: DeleteGroup :exec
delete from groups
where id = ?
limit 1
`

func (q *Queries) DeleteGroup(ctx context.Context, id int64) error {
	_, err := q.db.ExecContext(ctx, deleteGroup, id)
	return err
}

const deleteTribe = `-- name: DeleteTribe :exec
delete from tribes
where id = ?
limit 1
`

func (q *Queries) DeleteTribe(ctx context.Context, id int64) error {
	_, err := q.db.ExecContext(ctx, deleteTribe, id)
	return err
}

const getGroup = `-- name: GetGroup :one
select id, created_at, updated_at, name, short, size, grouping, tribe_id, image_id
from groups
where id = ?
limit 1
`

func (q *Queries) GetGroup(ctx context.Context, id int64) (Group, error) {
	row := q.db.QueryRowContext(ctx, getGroup, id)
	var i Group
	err := row.Scan(
		&i.ID,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.Name,
		&i.Short,
		&i.Size,
		&i.Grouping,
		&i.TribeID,
		&i.ImageID,
	)
	return i, err
}

const getIdentities = `-- name: GetIdentities :many
select id, idp_id, email, created_at, tribe_id, role
from identities
`

func (q *Queries) GetIdentities(ctx context.Context) ([]Identity, error) {
	rows, err := q.db.QueryContext(ctx, getIdentities)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []Identity
	for rows.Next() {
		var i Identity
		if err := rows.Scan(
			&i.ID,
			&i.IdpID,
			&i.Email,
			&i.CreatedAt,
			&i.TribeID,
			&i.Role,
		); 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 getIdentityByIdpId = `-- name: GetIdentityByIdpId :one
select id, idp_id, email, created_at, tribe_id, role
from identities
where idp_id = ?
limit 1
`

func (q *Queries) GetIdentityByIdpId(ctx context.Context, idpID string) (Identity, error) {
	row := q.db.QueryRowContext(ctx, getIdentityByIdpId, idpID)
	var i Identity
	err := row.Scan(
		&i.ID,
		&i.IdpID,
		&i.Email,
		&i.CreatedAt,
		&i.TribeID,
		&i.Role,
	)
	return i, err
}

const getSchedule = `-- name: GetSchedule :many
select id, start, "end", name, about
from schedule
order by "start" asc
`

func (q *Queries) GetSchedule(ctx context.Context) ([]Schedule, error) {
	rows, err := q.db.QueryContext(ctx, getSchedule)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []Schedule
	for rows.Next() {
		var i Schedule
		if err := rows.Scan(
			&i.ID,
			&i.Start,
			&i.End,
			&i.Name,
			&i.About,
		); 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 getTribe = `-- name: GetTribe :one
select id, updated_at, name, short, dpsg, image_id, email_domain, stavo_email
from tribes
where id = ?
limit 1
`

func (q *Queries) GetTribe(ctx context.Context, id int64) (Tribe, error) {
	row := q.db.QueryRowContext(ctx, getTribe, id)
	var i Tribe
	err := row.Scan(
		&i.ID,
		&i.UpdatedAt,
		&i.Name,
		&i.Short,
		&i.Dpsg,
		&i.ImageID,
		&i.EmailDomain,
		&i.StavoEmail,
	)
	return i, err
}

const listGroups = `-- name: ListGroups :many
select id, created_at, updated_at, name, short, size, grouping, tribe_id, image_id
from groups
`

func (q *Queries) ListGroups(ctx context.Context) ([]Group, error) {
	rows, err := q.db.QueryContext(ctx, listGroups)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []Group
	for rows.Next() {
		var i Group
		if err := rows.Scan(
			&i.ID,
			&i.CreatedAt,
			&i.UpdatedAt,
			&i.Name,
			&i.Short,
			&i.Size,
			&i.Grouping,
			&i.TribeID,
			&i.ImageID,
		); 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 listGroupsByTribe = `-- name: ListGroupsByTribe :many
select id, created_at, updated_at, name, short, size, grouping, tribe_id, image_id
from groups
where tribe_id = ?
`

func (q *Queries) ListGroupsByTribe(ctx context.Context, tribeID int64) ([]Group, error) {
	rows, err := q.db.QueryContext(ctx, listGroupsByTribe, tribeID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []Group
	for rows.Next() {
		var i Group
		if err := rows.Scan(
			&i.ID,
			&i.CreatedAt,
			&i.UpdatedAt,
			&i.Name,
			&i.Short,
			&i.Size,
			&i.Grouping,
			&i.TribeID,
			&i.ImageID,
		); 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 listTribes = `-- name: ListTribes :many
select id, updated_at, name, short, dpsg, image_id, email_domain, stavo_email
from tribes
`

func (q *Queries) ListTribes(ctx context.Context) ([]Tribe, error) {
	rows, err := q.db.QueryContext(ctx, listTribes)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []Tribe
	for rows.Next() {
		var i Tribe
		if err := rows.Scan(
			&i.ID,
			&i.UpdatedAt,
			&i.Name,
			&i.Short,
			&i.Dpsg,
			&i.ImageID,
			&i.EmailDomain,
			&i.StavoEmail,
		); 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
}
