// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.21.0
// source: payment.sql

package db

import (
	"context"
	"database/sql"
)

const createPayment = `-- name: CreatePayment :one
INSERT INTO payments (
    "account_id",
    "payment_category",
    "bankname",
    "IBAN",
    "BIC",
    "paypal_account",
    "paypal_id",
    "payment_system",
    "type",
    "creator",
    "changer"
) VALUES (
    $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11
) RETURNING id, account_id, payment_category, bankname, "IBAN", "BIC", paypal_account, paypal_id, payment_system, type, creator, created, changer, changed
`

type CreatePaymentParams struct {
	AccountID       int64          `json:"account_id"`
	PaymentCategory string         `json:"payment_category"`
	Bankname        sql.NullString `json:"bankname"`
	IBAN            sql.NullString `json:"IBAN"`
	BIC             sql.NullString `json:"BIC"`
	PaypalAccount   sql.NullString `json:"paypal_account"`
	PaypalID        sql.NullString `json:"paypal_id"`
	PaymentSystem   sql.NullString `json:"payment_system"`
	Type            string         `json:"type"`
	Creator         string         `json:"creator"`
	Changer         string         `json:"changer"`
}

func (q *Queries) CreatePayment(ctx context.Context, arg CreatePaymentParams) (Payment, error) {
	row := q.db.QueryRowContext(ctx, createPayment,
		arg.AccountID,
		arg.PaymentCategory,
		arg.Bankname,
		arg.IBAN,
		arg.BIC,
		arg.PaypalAccount,
		arg.PaypalID,
		arg.PaymentSystem,
		arg.Type,
		arg.Creator,
		arg.Changer,
	)
	var i Payment
	err := row.Scan(
		&i.ID,
		&i.AccountID,
		&i.PaymentCategory,
		&i.Bankname,
		&i.IBAN,
		&i.BIC,
		&i.PaypalAccount,
		&i.PaypalID,
		&i.PaymentSystem,
		&i.Type,
		&i.Creator,
		&i.Created,
		&i.Changer,
		&i.Changed,
	)
	return i, err
}

const deletePayment = `-- name: DeletePayment :exec
DELETE FROM payments
WHERE "id" = $1
`

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

const getPayment = `-- name: GetPayment :one
SELECT id, account_id, payment_category, bankname, "IBAN", "BIC", paypal_account, paypal_id, payment_system, type, creator, created, changer, changed FROM payments
WHERE "id" = $1 LIMIT 1
`

func (q *Queries) GetPayment(ctx context.Context, id int64) (Payment, error) {
	row := q.db.QueryRowContext(ctx, getPayment, id)
	var i Payment
	err := row.Scan(
		&i.ID,
		&i.AccountID,
		&i.PaymentCategory,
		&i.Bankname,
		&i.IBAN,
		&i.BIC,
		&i.PaypalAccount,
		&i.PaypalID,
		&i.PaymentSystem,
		&i.Type,
		&i.Creator,
		&i.Created,
		&i.Changer,
		&i.Changed,
	)
	return i, err
}

const listPayments = `-- name: ListPayments :many
SELECT id, account_id, payment_category, bankname, "IBAN", "BIC", paypal_account, paypal_id, payment_system, type, creator, created, changer, changed FROM payments
ORDER BY "payment_category"
LIMIT $1
OFFSET $2
`

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

func (q *Queries) ListPayments(ctx context.Context, arg ListPaymentsParams) ([]Payment, error) {
	rows, err := q.db.QueryContext(ctx, listPayments, arg.Limit, arg.Offset)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	items := []Payment{}
	for rows.Next() {
		var i Payment
		if err := rows.Scan(
			&i.ID,
			&i.AccountID,
			&i.PaymentCategory,
			&i.Bankname,
			&i.IBAN,
			&i.BIC,
			&i.PaypalAccount,
			&i.PaypalID,
			&i.PaymentSystem,
			&i.Type,
			&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 updatePayment = `-- name: UpdatePayment :one
UPDATE payments
SET
    "account_id" = COALESCE($3, "account_id"),
    "payment_category" = COALESCE($4, "payment_category"),
    "bankname" = COALESCE($5, "bankname"),
    "IBAN" = COALESCE($6, "IBAN"),
    "BIC" = COALESCE($7, "BIC"),
    "paypal_account" = COALESCE($8, "paypal_account"),
    "paypal_id" = COALESCE($9, "paypal_id"),
    "payment_system" = COALESCE($10, "payment_system"),
    "type" = COALESCE($11, "type"),
    "changer" = $2,
    "changed" = now()
WHERE "id" = $1
RETURNING id, account_id, payment_category, bankname, "IBAN", "BIC", paypal_account, paypal_id, payment_system, type, creator, created, changer, changed
`

type UpdatePaymentParams struct {
	ID              int64          `json:"id"`
	Changer         string         `json:"changer"`
	AccountID       sql.NullInt64  `json:"account_id"`
	PaymentCategory sql.NullString `json:"payment_category"`
	Bankname        sql.NullString `json:"bankname"`
	Iban            sql.NullString `json:"iban"`
	Bic             sql.NullString `json:"bic"`
	PaypalAccount   sql.NullString `json:"paypal_account"`
	PaypalID        sql.NullString `json:"paypal_id"`
	PaymentSystem   sql.NullString `json:"payment_system"`
	Type            sql.NullString `json:"type"`
}

func (q *Queries) UpdatePayment(ctx context.Context, arg UpdatePaymentParams) (Payment, error) {
	row := q.db.QueryRowContext(ctx, updatePayment,
		arg.ID,
		arg.Changer,
		arg.AccountID,
		arg.PaymentCategory,
		arg.Bankname,
		arg.Iban,
		arg.Bic,
		arg.PaypalAccount,
		arg.PaypalID,
		arg.PaymentSystem,
		arg.Type,
	)
	var i Payment
	err := row.Scan(
		&i.ID,
		&i.AccountID,
		&i.PaymentCategory,
		&i.Bankname,
		&i.IBAN,
		&i.BIC,
		&i.PaypalAccount,
		&i.PaypalID,
		&i.PaymentSystem,
		&i.Type,
		&i.Creator,
		&i.Created,
		&i.Changer,
		&i.Changed,
	)
	return i, err
}
