// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.22.0
// source: account_info.sql

package db

import (
	"context"
	"database/sql"
	"time"
)

const createAccountInfo = `-- name: CreateAccountInfo :one
INSERT INTO account_info (
    "account_id",
    "privacy_accepted",
    "privacy_accepted_date",
    "firstname",
    "lastname",
    "birthday",
    "phone",
    "city",
    "zip",
    "street",
    "country",
    "creator",
    "changer"
) VALUES (
    $1,
    $2,
    $3,
    $4,
    $5,
    $6,
    $7,
    $8,
    $9,
    $10,
    $11,
    $12,
    $12
) RETURNING account_id, firstname, lastname, birthday, privacy_accepted, privacy_accepted_date, phone, city, zip, street, country, creator, created, changer, changed
`

type CreateAccountInfoParams struct {
	AccountID           uint64         `json:"account_id"`
	PrivacyAccepted     sql.NullBool   `json:"privacy_accepted"`
	PrivacyAcceptedDate sql.NullTime   `json:"privacy_accepted_date"`
	Firstname           string         `json:"firstname"`
	Lastname            string         `json:"lastname"`
	Birthday            time.Time      `json:"birthday"`
	Phone               sql.NullString `json:"phone"`
	City                string         `json:"city"`
	Zip                 string         `json:"zip"`
	Street              string         `json:"street"`
	Country             string         `json:"country"`
	Creator             string         `json:"creator"`
}

func (q *Queries) CreateAccountInfo(ctx context.Context, arg CreateAccountInfoParams) (AccountInfo, error) {
	row := q.db.QueryRowContext(ctx, createAccountInfo,
		arg.AccountID,
		arg.PrivacyAccepted,
		arg.PrivacyAcceptedDate,
		arg.Firstname,
		arg.Lastname,
		arg.Birthday,
		arg.Phone,
		arg.City,
		arg.Zip,
		arg.Street,
		arg.Country,
		arg.Creator,
	)
	var i AccountInfo
	err := row.Scan(
		&i.AccountID,
		&i.Firstname,
		&i.Lastname,
		&i.Birthday,
		&i.PrivacyAccepted,
		&i.PrivacyAcceptedDate,
		&i.Phone,
		&i.City,
		&i.Zip,
		&i.Street,
		&i.Country,
		&i.Creator,
		&i.Created,
		&i.Changer,
		&i.Changed,
	)
	return i, err
}

const deleteAccountInfo = `-- name: DeleteAccountInfo :exec
DELETE FROM account_info
WHERE "account_id" = $1
`

func (q *Queries) DeleteAccountInfo(ctx context.Context, accountID uint64) error {
	_, err := q.db.ExecContext(ctx, deleteAccountInfo, accountID)
	return err
}

const getAccountInfo = `-- name: GetAccountInfo :one
SELECT account_id, firstname, lastname, birthday, privacy_accepted, privacy_accepted_date, phone, city, zip, street, country, creator, created, changer, changed FROM account_info
WHERE "account_id" = $1 LIMIT 1
`

func (q *Queries) GetAccountInfo(ctx context.Context, accountID uint64) (AccountInfo, error) {
	row := q.db.QueryRowContext(ctx, getAccountInfo, accountID)
	var i AccountInfo
	err := row.Scan(
		&i.AccountID,
		&i.Firstname,
		&i.Lastname,
		&i.Birthday,
		&i.PrivacyAccepted,
		&i.PrivacyAcceptedDate,
		&i.Phone,
		&i.City,
		&i.Zip,
		&i.Street,
		&i.Country,
		&i.Creator,
		&i.Created,
		&i.Changer,
		&i.Changed,
	)
	return i, err
}

const listAccountInfo = `-- name: ListAccountInfo :many
SELECT account_id, firstname, lastname, birthday, privacy_accepted, privacy_accepted_date, phone, city, zip, street, country, creator, created, changer, changed FROM account_info
ORDER BY "lastname", "firstname"
LIMIT $1
OFFSET $2
`

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

func (q *Queries) ListAccountInfo(ctx context.Context, arg ListAccountInfoParams) ([]AccountInfo, error) {
	rows, err := q.db.QueryContext(ctx, listAccountInfo, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []AccountInfo{}
	for rows.Next() {
		var i AccountInfo
		if err := rows.Scan(
			&i.AccountID,
			&i.Firstname,
			&i.Lastname,
			&i.Birthday,
			&i.PrivacyAccepted,
			&i.PrivacyAcceptedDate,
			&i.Phone,
			&i.City,
			&i.Zip,
			&i.Street,
			&i.Country,
			&i.Creator,
			&i.Created,
			&i.Changer,
			&i.Changed,
		); 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 updateAccountInfo = `-- name: UpdateAccountInfo :one
UPDATE account_info
SET
    "firstname" = COALESCE($3, "firstname"),
    "lastname" = COALESCE($4, "lastname"),
    "birthday" = COALESCE($5, "birthday"),
    "phone" = COALESCE($6, "phone"),
    "city" = COALESCE($7, "city"),
    "zip" = COALESCE($8, "zip"),
    "street" = COALESCE($9, "street"),
    "country" = COALESCE($10, "country"),
    "changer" = $2,
    "changed" = now()
WHERE "account_id" = $1
RETURNING account_id, firstname, lastname, birthday, privacy_accepted, privacy_accepted_date, phone, city, zip, street, country, creator, created, changer, changed
`

type UpdateAccountInfoParams struct {
	AccountID uint64         `json:"account_id"`
	Changer   string         `json:"changer"`
	Firstname sql.NullString `json:"firstname"`
	Lastname  sql.NullString `json:"lastname"`
	Birthday  sql.NullTime   `json:"birthday"`
	Phone     sql.NullString `json:"phone"`
	City      sql.NullString `json:"city"`
	Zip       sql.NullString `json:"zip"`
	Street    sql.NullString `json:"street"`
	Country   sql.NullString `json:"country"`
}

func (q *Queries) UpdateAccountInfo(ctx context.Context, arg UpdateAccountInfoParams) (AccountInfo, error) {
	row := q.db.QueryRowContext(ctx, updateAccountInfo,
		arg.AccountID,
		arg.Changer,
		arg.Firstname,
		arg.Lastname,
		arg.Birthday,
		arg.Phone,
		arg.City,
		arg.Zip,
		arg.Street,
		arg.Country,
	)
	var i AccountInfo
	err := row.Scan(
		&i.AccountID,
		&i.Firstname,
		&i.Lastname,
		&i.Birthday,
		&i.PrivacyAccepted,
		&i.PrivacyAcceptedDate,
		&i.Phone,
		&i.City,
		&i.Zip,
		&i.Street,
		&i.Country,
		&i.Creator,
		&i.Created,
		&i.Changer,
		&i.Changed,
	)
	return i, err
}

const updateAccountPrivacy = `-- name: UpdateAccountPrivacy :one
UPDATE account_info
SET
    "privacy_accepted" = $1,
    "privacy_accepted_date" = $2,
    "changer" = $3,
    "changed" = now()
WHERE "account_id" = $4
RETURNING account_id, firstname, lastname, birthday, privacy_accepted, privacy_accepted_date, phone, city, zip, street, country, creator, created, changer, changed
`

type UpdateAccountPrivacyParams struct {
	PrivacyAccepted     sql.NullBool `json:"privacy_accepted"`
	PrivacyAcceptedDate sql.NullTime `json:"privacy_accepted_date"`
	Changer             string       `json:"changer"`
	ID                  uint64       `json:"id"`
}

func (q *Queries) UpdateAccountPrivacy(ctx context.Context, arg UpdateAccountPrivacyParams) (AccountInfo, error) {
	row := q.db.QueryRowContext(ctx, updateAccountPrivacy,
		arg.PrivacyAccepted,
		arg.PrivacyAcceptedDate,
		arg.Changer,
		arg.ID,
	)
	var i AccountInfo
	err := row.Scan(
		&i.AccountID,
		&i.Firstname,
		&i.Lastname,
		&i.Birthday,
		&i.PrivacyAccepted,
		&i.PrivacyAcceptedDate,
		&i.Phone,
		&i.City,
		&i.Zip,
		&i.Street,
		&i.Country,
		&i.Creator,
		&i.Created,
		&i.Changer,
		&i.Changed,
	)
	return i, err
}