// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.30.0
// source: attendees.sql

package repository

import (
	"context"

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

const createAttendee = `-- name: CreateAttendee :one
INSERT INTO event_attendees (id, event_id, user_id, email, status)
VALUES ($1, $2, $3, $4, 'pending')
RETURNING id, event_id, user_id, email, status
`

type CreateAttendeeParams struct {
	ID      pgtype.UUID `json:"id"`
	EventID pgtype.UUID `json:"event_id"`
	UserID  pgtype.UUID `json:"user_id"`
	Email   pgtype.Text `json:"email"`
}

func (q *Queries) CreateAttendee(ctx context.Context, arg CreateAttendeeParams) (EventAttendee, error) {
	row := q.db.QueryRow(ctx, createAttendee,
		arg.ID,
		arg.EventID,
		arg.UserID,
		arg.Email,
	)
	var i EventAttendee
	err := row.Scan(
		&i.ID,
		&i.EventID,
		&i.UserID,
		&i.Email,
		&i.Status,
	)
	return i, err
}

const deleteAttendee = `-- name: DeleteAttendee :exec
DELETE FROM event_attendees
WHERE id = $1 AND event_id = $2
`

type DeleteAttendeeParams struct {
	ID      pgtype.UUID `json:"id"`
	EventID pgtype.UUID `json:"event_id"`
}

func (q *Queries) DeleteAttendee(ctx context.Context, arg DeleteAttendeeParams) error {
	_, err := q.db.Exec(ctx, deleteAttendee, arg.ID, arg.EventID)
	return err
}

const getAttendeeByID = `-- name: GetAttendeeByID :one
SELECT id, event_id, user_id, email, status
FROM event_attendees
WHERE id = $1
`

func (q *Queries) GetAttendeeByID(ctx context.Context, id pgtype.UUID) (EventAttendee, error) {
	row := q.db.QueryRow(ctx, getAttendeeByID, id)
	var i EventAttendee
	err := row.Scan(
		&i.ID,
		&i.EventID,
		&i.UserID,
		&i.Email,
		&i.Status,
	)
	return i, err
}

const listAttendeesByEvent = `-- name: ListAttendeesByEvent :many
SELECT id, event_id, user_id, email, status
FROM event_attendees
WHERE event_id = $1
ORDER BY id ASC
`

func (q *Queries) ListAttendeesByEvent(ctx context.Context, eventID pgtype.UUID) ([]EventAttendee, error) {
	rows, err := q.db.Query(ctx, listAttendeesByEvent, eventID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []EventAttendee{}
	for rows.Next() {
		var i EventAttendee
		if err := rows.Scan(
			&i.ID,
			&i.EventID,
			&i.UserID,
			&i.Email,
			&i.Status,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const updateAttendeeStatus = `-- name: UpdateAttendeeStatus :one
UPDATE event_attendees
SET status = $2
WHERE id = $1
RETURNING id, event_id, user_id, email, status
`

type UpdateAttendeeStatusParams struct {
	ID     pgtype.UUID `json:"id"`
	Status string      `json:"status"`
}

func (q *Queries) UpdateAttendeeStatus(ctx context.Context, arg UpdateAttendeeStatusParams) (EventAttendee, error) {
	row := q.db.QueryRow(ctx, updateAttendeeStatus, arg.ID, arg.Status)
	var i EventAttendee
	err := row.Scan(
		&i.ID,
		&i.EventID,
		&i.UserID,
		&i.Email,
		&i.Status,
	)
	return i, err
}
