// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.26.0
// source: invite.sql

package invite

import (
	"context"
)

const activate = `-- name: Activate :one
UPDATE invites
SET is_activated = true
WHERE id = ?
  AND is_activated IS FALSE
  AND deleted_at IS NULL
RETURNING id, user_id, invite_hash, is_activated, created_at, updated_at, deleted_at
`

// Activate
//
//	UPDATE invites
//	SET is_activated = true
//	WHERE id = ?
//	  AND is_activated IS FALSE
//	  AND deleted_at IS NULL
//	RETURNING id, user_id, invite_hash, is_activated, created_at, updated_at, deleted_at
func (q *Queries) Activate(ctx context.Context, id int64) (*Invite, error) {
	row := q.queryRow(ctx, q.activateStmt, activate, id)
	var i Invite
	err := row.Scan(
		&i.ID,
		&i.UserID,
		&i.InviteHash,
		&i.IsActivated,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.DeletedAt,
	)
	return &i, err
}

const createOrUpdate = `-- name: CreateOrUpdate :one
INSERT INTO invites (user_id, invite_hash, is_activated)
VALUES (?, ?, false)
ON CONFLICT (user_id, is_activated) WHERE is_activated IS FALSE DO UPDATE
SET invite_hash = excluded.invite_hash, updated_at = datetime('now')
RETURNING id, user_id, invite_hash, is_activated, created_at, updated_at, deleted_at
`

type CreateOrUpdateParams struct {
	UserID     int64  `json:"userId"`
	InviteHash string `json:"inviteHash"`
}

// CreateOrUpdate
//
//	INSERT INTO invites (user_id, invite_hash, is_activated)
//	VALUES (?, ?, false)
//	ON CONFLICT (user_id, is_activated) WHERE is_activated IS FALSE DO UPDATE
//	SET invite_hash = excluded.invite_hash, updated_at = datetime('now')
//	RETURNING id, user_id, invite_hash, is_activated, created_at, updated_at, deleted_at
func (q *Queries) CreateOrUpdate(ctx context.Context, arg CreateOrUpdateParams) (*Invite, error) {
	row := q.queryRow(ctx, q.createOrUpdateStmt, createOrUpdate, arg.UserID, arg.InviteHash)
	var i Invite
	err := row.Scan(
		&i.ID,
		&i.UserID,
		&i.InviteHash,
		&i.IsActivated,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.DeletedAt,
	)
	return &i, err
}

const delete = `-- name: Delete :exec
UPDATE invites
SET deleted_at = datetime('now'), is_activated = true
WHERE id = ?
  AND deleted_at IS NULL
`

// Delete
//
//	UPDATE invites
//	SET deleted_at = datetime('now'), is_activated = true
//	WHERE id = ?
//	  AND deleted_at IS NULL
func (q *Queries) Delete(ctx context.Context, id int64) error {
	_, err := q.exec(ctx, q.deleteStmt, delete, id)
	return err
}

const getActiveByUserID = `-- name: GetActiveByUserID :one
SELECT id, user_id, invite_hash, is_activated, created_at, updated_at, deleted_at
FROM invites
WHERE id = ?
  AND is_activated IS FALSE
  AND deleted_at IS NULL
`

// GetActiveByUserID
//
//	SELECT id, user_id, invite_hash, is_activated, created_at, updated_at, deleted_at
//	FROM invites
//	WHERE id = ?
//	  AND is_activated IS FALSE
//	  AND deleted_at IS NULL
func (q *Queries) GetActiveByUserID(ctx context.Context, id int64) (*Invite, error) {
	row := q.queryRow(ctx, q.getActiveByUserIDStmt, getActiveByUserID, id)
	var i Invite
	err := row.Scan(
		&i.ID,
		&i.UserID,
		&i.InviteHash,
		&i.IsActivated,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.DeletedAt,
	)
	return &i, err
}

const getAllByUserID = `-- name: GetAllByUserID :many
SELECT id, user_id, invite_hash, is_activated, created_at, updated_at, deleted_at
FROM invites
WHERE user_id = ?
  AND deleted_at IS NULL
`

// GetAllByUserID
//
//	SELECT id, user_id, invite_hash, is_activated, created_at, updated_at, deleted_at
//	FROM invites
//	WHERE user_id = ?
//	  AND deleted_at IS NULL
func (q *Queries) GetAllByUserID(ctx context.Context, userID int64) ([]*Invite, error) {
	rows, err := q.query(ctx, q.getAllByUserIDStmt, getAllByUserID, userID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []*Invite{}
	for rows.Next() {
		var i Invite
		if err := rows.Scan(
			&i.ID,
			&i.UserID,
			&i.InviteHash,
			&i.IsActivated,
			&i.CreatedAt,
			&i.UpdatedAt,
			&i.DeletedAt,
		); 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 getByID = `-- name: GetByID :one
SELECT id, user_id, invite_hash, is_activated, created_at, updated_at, deleted_at
FROM invites
WHERE id = ?
  AND deleted_at IS NULL
`

// GetByID
//
//	SELECT id, user_id, invite_hash, is_activated, created_at, updated_at, deleted_at
//	FROM invites
//	WHERE id = ?
//	  AND deleted_at IS NULL
func (q *Queries) GetByID(ctx context.Context, id int64) (*Invite, error) {
	row := q.queryRow(ctx, q.getByIDStmt, getByID, id)
	var i Invite
	err := row.Scan(
		&i.ID,
		&i.UserID,
		&i.InviteHash,
		&i.IsActivated,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.DeletedAt,
	)
	return &i, err
}

const getByInviteHash = `-- name: GetByInviteHash :one
SELECT id, user_id, invite_hash, is_activated, created_at, updated_at, deleted_at
FROM invites
WHERE invite_hash = ?
  AND is_activated IS FALSE
  AND deleted_at IS NULL
`

// GetByInviteHash
//
//	SELECT id, user_id, invite_hash, is_activated, created_at, updated_at, deleted_at
//	FROM invites
//	WHERE invite_hash = ?
//	  AND is_activated IS FALSE
//	  AND deleted_at IS NULL
func (q *Queries) GetByInviteHash(ctx context.Context, inviteHash string) (*Invite, error) {
	row := q.queryRow(ctx, q.getByInviteHashStmt, getByInviteHash, inviteHash)
	var i Invite
	err := row.Scan(
		&i.ID,
		&i.UserID,
		&i.InviteHash,
		&i.IsActivated,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.DeletedAt,
	)
	return &i, err
}
