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

package repository

import (
	"context"
	"time"
)

const createNewsEntry = `-- name: CreateNewsEntry :exec
INSERT INTO news (
    news_title, news_text, news_date,
    news_publish, display
) VALUES (?, ?, ?, ?, ?)
`

type CreateNewsEntryParams struct {
	NewsTitle   string     `db:"news_title" json:"newsTitle"`
	NewsText    string     `db:"news_text" json:"newsText"`
	NewsDate    *time.Time `db:"news_date" json:"newsDate"`
	NewsPublish *time.Time `db:"news_publish" json:"newsPublish"`
	Display     int64      `db:"display" json:"display"`
}

func (q *Queries) CreateNewsEntry(ctx context.Context, arg CreateNewsEntryParams) error {
	_, err := q.db.ExecContext(ctx, createNewsEntry,
		arg.NewsTitle,
		arg.NewsText,
		arg.NewsDate,
		arg.NewsPublish,
		arg.Display,
	)
	return err
}

const createRetailer = `-- name: CreateRetailer :exec
INSERT INTO retailer (
    shopname, url, country, display
) VALUES (?, ?, ?, ?)
`

type CreateRetailerParams struct {
	Shopname string `db:"shopname" json:"shopname"`
	Url      string `db:"url" json:"url"`
	Country  string `db:"country" json:"country"`
	Display  int64  `db:"display" json:"display"`
}

func (q *Queries) CreateRetailer(ctx context.Context, arg CreateRetailerParams) error {
	_, err := q.db.ExecContext(ctx, createRetailer,
		arg.Shopname,
		arg.Url,
		arg.Country,
		arg.Display,
	)
	return err
}

const createUser = `-- name: CreateUser :exec
INSERT INTO app_user (
    user_name, user_pass
)
VALUES (?, ?)
`

type CreateUserParams struct {
	UserName string  `db:"user_name" json:"userName"`
	UserPass *string `db:"user_pass" json:"userPass"`
}

func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) error {
	_, err := q.db.ExecContext(ctx, createUser, arg.UserName, arg.UserPass)
	return err
}

const deleteNewsEntry = `-- name: DeleteNewsEntry :exec
DELETE FROM news
WHERE id = ?
`

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

const deleteRetailer = `-- name: DeleteRetailer :exec
DELETE FROM news
WHERE id = ?
`

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

const deleteUser = `-- name: DeleteUser :exec
DELETE FROM app_user
WHERE user_name = ?
`

func (q *Queries) DeleteUser(ctx context.Context, userName string) error {
	_, err := q.db.ExecContext(ctx, deleteUser, userName)
	return err
}

const getNewsEntry = `-- name: GetNewsEntry :one
SELECT id, news_title, news_text, news_date, news_publish, display FROM news
WHERE id = ? LIMIT 1
`

func (q *Queries) GetNewsEntry(ctx context.Context, id int64) (News, error) {
	row := q.db.QueryRowContext(ctx, getNewsEntry, id)
	var i News
	err := row.Scan(
		&i.ID,
		&i.NewsTitle,
		&i.NewsText,
		&i.NewsDate,
		&i.NewsPublish,
		&i.Display,
	)
	return i, err
}

const getUser = `-- name: GetUser :one
SELECT user_name, user_pass, realname, email FROM app_user
WHERE user_name = ? LIMIT 1
`

func (q *Queries) GetUser(ctx context.Context, userName string) (AppUser, error) {
	row := q.db.QueryRowContext(ctx, getUser, userName)
	var i AppUser
	err := row.Scan(
		&i.UserName,
		&i.UserPass,
		&i.Realname,
		&i.Email,
	)
	return i, err
}

const listActiveNews = `-- name: ListActiveNews :many
SELECT id, news_title, news_text, news_date, news_publish, display FROM news
WHERE display = 1
ORDER BY news_date
`

func (q *Queries) ListActiveNews(ctx context.Context) ([]News, error) {
	rows, err := q.db.QueryContext(ctx, listActiveNews)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []News
	for rows.Next() {
		var i News
		if err := rows.Scan(
			&i.ID,
			&i.NewsTitle,
			&i.NewsText,
			&i.NewsDate,
			&i.NewsPublish,
			&i.Display,
		); 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 listActiveRetailers = `-- name: ListActiveRetailers :many
SELECT id, shopname, url, country, display FROM retailer
WHERE display = 1
ORDER BY shopname
`

func (q *Queries) ListActiveRetailers(ctx context.Context) ([]Retailer, error) {
	rows, err := q.db.QueryContext(ctx, listActiveRetailers)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []Retailer
	for rows.Next() {
		var i Retailer
		if err := rows.Scan(
			&i.ID,
			&i.Shopname,
			&i.Url,
			&i.Country,
			&i.Display,
		); 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 listNews = `-- name: ListNews :many
SELECT id, news_title, news_text, news_date, news_publish, display FROM news
ORDER BY news_date
`

func (q *Queries) ListNews(ctx context.Context) ([]News, error) {
	rows, err := q.db.QueryContext(ctx, listNews)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []News
	for rows.Next() {
		var i News
		if err := rows.Scan(
			&i.ID,
			&i.NewsTitle,
			&i.NewsText,
			&i.NewsDate,
			&i.NewsPublish,
			&i.Display,
		); 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 listRetailers = `-- name: ListRetailers :many
SELECT id, shopname, url, country, display FROM retailer
ORDER BY shopname
`

func (q *Queries) ListRetailers(ctx context.Context) ([]Retailer, error) {
	rows, err := q.db.QueryContext(ctx, listRetailers)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []Retailer
	for rows.Next() {
		var i Retailer
		if err := rows.Scan(
			&i.ID,
			&i.Shopname,
			&i.Url,
			&i.Country,
			&i.Display,
		); 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 listUsers = `-- name: ListUsers :many
SELECT user_name, user_pass, realname, email FROM app_user
ORDER BY user_name
`

func (q *Queries) ListUsers(ctx context.Context) ([]AppUser, error) {
	rows, err := q.db.QueryContext(ctx, listUsers)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []AppUser
	for rows.Next() {
		var i AppUser
		if err := rows.Scan(
			&i.UserName,
			&i.UserPass,
			&i.Realname,
			&i.Email,
		); 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 updateNewsEntry = `-- name: UpdateNewsEntry :exec
UPDATE news
SET
    news_title = ?, news_text = ?,
    news_date = ?, news_publish = ?, display = ?
WHERE id = ?
`

type UpdateNewsEntryParams struct {
	NewsTitle   string     `db:"news_title" json:"newsTitle"`
	NewsText    string     `db:"news_text" json:"newsText"`
	NewsDate    *time.Time `db:"news_date" json:"newsDate"`
	NewsPublish *time.Time `db:"news_publish" json:"newsPublish"`
	Display     int64      `db:"display" json:"display"`
	ID          int64      `db:"id" json:"id"`
}

func (q *Queries) UpdateNewsEntry(ctx context.Context, arg UpdateNewsEntryParams) error {
	_, err := q.db.ExecContext(ctx, updateNewsEntry,
		arg.NewsTitle,
		arg.NewsText,
		arg.NewsDate,
		arg.NewsPublish,
		arg.Display,
		arg.ID,
	)
	return err
}

const updateRetailer = `-- name: UpdateRetailer :exec
UPDATE retailer
SET shopname = ?, url = ?, country = ?, display = ?
WHERE id = ?
`

type UpdateRetailerParams struct {
	Shopname string `db:"shopname" json:"shopname"`
	Url      string `db:"url" json:"url"`
	Country  string `db:"country" json:"country"`
	Display  int64  `db:"display" json:"display"`
	ID       int64  `db:"id" json:"id"`
}

func (q *Queries) UpdateRetailer(ctx context.Context, arg UpdateRetailerParams) error {
	_, err := q.db.ExecContext(ctx, updateRetailer,
		arg.Shopname,
		arg.Url,
		arg.Country,
		arg.Display,
		arg.ID,
	)
	return err
}

const updateUser = `-- name: UpdateUser :exec
UPDATE app_user
SET user_pass = ?
WHERE user_name = ?
`

type UpdateUserParams struct {
	UserPass *string `db:"user_pass" json:"userPass"`
	UserName string  `db:"user_name" json:"userName"`
}

func (q *Queries) UpdateUser(ctx context.Context, arg UpdateUserParams) error {
	_, err := q.db.ExecContext(ctx, updateUser, arg.UserPass, arg.UserName)
	return err
}
