// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.15.0
// source: events.sql

package db

import (
	"context"
	"time"
)

const createEvent = `-- name: CreateEvent :one
INSERT INTO events ("name", location_id, datetime)
VALUES ($1, $2, $3)
RETURNING id, location_id, name, datetime, created_at
`

type CreateEventParams struct {
	Name       string `json:"name"`
	LocationID int64  `json:"location_id"`
	Datetime   int64  `json:"datetime"`
}

func (q *Queries) CreateEvent(ctx context.Context, arg CreateEventParams) (Events, error) {
	row := q.db.QueryRowContext(ctx, createEvent, arg.Name, arg.LocationID, arg.Datetime)
	var i Events
	err := row.Scan(
		&i.ID,
		&i.LocationID,
		&i.Name,
		&i.Datetime,
		&i.CreatedAt,
	)
	return i, err
}

const deleteEvent = `-- name: DeleteEvent :one
DELETE
FROM events
WHERE id = $1
RETURNING id, location_id, name, datetime, created_at
`

func (q *Queries) DeleteEvent(ctx context.Context, id int64) (Events, error) {
	row := q.db.QueryRowContext(ctx, deleteEvent, id)
	var i Events
	err := row.Scan(
		&i.ID,
		&i.LocationID,
		&i.Name,
		&i.Datetime,
		&i.CreatedAt,
	)
	return i, err
}

const getEventById = `-- name: GetEventById :one
SELECT id, location_id, name, datetime, created_at
FROM events
WHERE id = $1
LIMIT 1
`

func (q *Queries) GetEventById(ctx context.Context, id int64) (Events, error) {
	row := q.db.QueryRowContext(ctx, getEventById, id)
	var i Events
	err := row.Scan(
		&i.ID,
		&i.LocationID,
		&i.Name,
		&i.Datetime,
		&i.CreatedAt,
	)
	return i, err
}

const getEventListByOffsetLimit = `-- name: GetEventListByOffsetLimit :many
SELECT events.id         as id,
       events.name       as name,
       "datetime",
       location_id,
       locations.name    as location,
       events.created_at as created_at
FROM events
         INNER JOIN locations on locations.id = events.location_id
ORDER BY events.created_at
OFFSET $1 LIMIT $2
`

type GetEventListByOffsetLimitParams struct {
	Offset int32 `json:"offset"`
	Limit  int32 `json:"limit"`
}

type GetEventListByOffsetLimitRow struct {
	ID         int64     `json:"id"`
	Name       string    `json:"name"`
	Datetime   int64     `json:"datetime"`
	LocationID int64     `json:"location_id"`
	Location   string    `json:"location"`
	CreatedAt  time.Time `json:"created_at"`
}

func (q *Queries) GetEventListByOffsetLimit(ctx context.Context, arg GetEventListByOffsetLimitParams) ([]GetEventListByOffsetLimitRow, error) {
	rows, err := q.db.QueryContext(ctx, getEventListByOffsetLimit, arg.Offset, arg.Limit)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []GetEventListByOffsetLimitRow{}
	for rows.Next() {
		var i GetEventListByOffsetLimitRow
		if err := rows.Scan(
			&i.ID,
			&i.Name,
			&i.Datetime,
			&i.LocationID,
			&i.Location,
			&i.CreatedAt,
		); 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 getEventWithLocationById = `-- name: GetEventWithLocationById :one
SELECT events.id         as id,
       events.name       as name,
       "datetime",
       location_id,
       locations.name    as location,
       events.created_at as created_at
FROM events
         INNER JOIN locations on locations.id = events.location_id
WHERE events.id = $1
LIMIT 1
`

type GetEventWithLocationByIdRow struct {
	ID         int64     `json:"id"`
	Name       string    `json:"name"`
	Datetime   int64     `json:"datetime"`
	LocationID int64     `json:"location_id"`
	Location   string    `json:"location"`
	CreatedAt  time.Time `json:"created_at"`
}

func (q *Queries) GetEventWithLocationById(ctx context.Context, id int64) (GetEventWithLocationByIdRow, error) {
	row := q.db.QueryRowContext(ctx, getEventWithLocationById, id)
	var i GetEventWithLocationByIdRow
	err := row.Scan(
		&i.ID,
		&i.Name,
		&i.Datetime,
		&i.LocationID,
		&i.Location,
		&i.CreatedAt,
	)
	return i, err
}

const updateEvent = `-- name: UpdateEvent :one
UPDATE events
SET "name"=$2,
    location_id=$3,
    datetime=$4
WHERE id = $1
RETURNING id, location_id, name, datetime, created_at
`

type UpdateEventParams struct {
	ID         int64  `json:"id"`
	Name       string `json:"name"`
	LocationID int64  `json:"location_id"`
	Datetime   int64  `json:"datetime"`
}

func (q *Queries) UpdateEvent(ctx context.Context, arg UpdateEventParams) (Events, error) {
	row := q.db.QueryRowContext(ctx, updateEvent,
		arg.ID,
		arg.Name,
		arg.LocationID,
		arg.Datetime,
	)
	var i Events
	err := row.Scan(
		&i.ID,
		&i.LocationID,
		&i.Name,
		&i.Datetime,
		&i.CreatedAt,
	)
	return i, err
}
