// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.27.0
// source: user.sql

package repo

import (
	"context"
	"time"
)

const createUser = `-- name: CreateUser :one
INSERT INTO users (
    email,
    password_hash
) VALUES (
    $1, $2
) RETURNING id,email
`

type CreateUserParams struct {
	Email        string `json:"email"`
	PasswordHash string `json:"password_hash"`
}

type CreateUserRow struct {
	ID    int32  `json:"id"`
	Email string `json:"email"`
}

func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (CreateUserRow, error) {
	row := q.db.QueryRowContext(ctx, createUser, arg.Email, arg.PasswordHash)
	var i CreateUserRow
	err := row.Scan(&i.ID, &i.Email)
	return i, err
}

const getUserByEmail = `-- name: GetUserByEmail :one
SELECT id, password_hash, email
FROM users
WHERE email = $1
`

type GetUserByEmailRow struct {
	ID           int32  `json:"id"`
	PasswordHash string `json:"password_hash"`
	Email        string `json:"email"`
}

func (q *Queries) GetUserByEmail(ctx context.Context, email string) (GetUserByEmailRow, error) {
	row := q.db.QueryRowContext(ctx, getUserByEmail, email)
	var i GetUserByEmailRow
	err := row.Scan(&i.ID, &i.PasswordHash, &i.Email)
	return i, err
}

const isEmailAvaliable = `-- name: IsEmailAvaliable :one
SELECT NOT EXISTS (
    SELECT 1 from users
    WHERE email = $1
)
`

func (q *Queries) IsEmailAvaliable(ctx context.Context, email string) (bool, error) {
	row := q.db.QueryRowContext(ctx, isEmailAvaliable, email)
	var not_exists bool
	err := row.Scan(&not_exists)
	return not_exists, err
}

const updatePasswordByEmail = `-- name: UpdatePasswordByEmail :one
UPDATE users
SET password_hash = $1, updated_at = $2
WHERE email = $3
RETURNING id, email
`

type UpdatePasswordByEmailParams struct {
	PasswordHash string    `json:"password_hash"`
	UpdatedAt    time.Time `json:"updated_at"`
	Email        string    `json:"email"`
}

type UpdatePasswordByEmailRow struct {
	ID    int32  `json:"id"`
	Email string `json:"email"`
}

func (q *Queries) UpdatePasswordByEmail(ctx context.Context, arg UpdatePasswordByEmailParams) (UpdatePasswordByEmailRow, error) {
	row := q.db.QueryRowContext(ctx, updatePasswordByEmail, arg.PasswordHash, arg.UpdatedAt, arg.Email)
	var i UpdatePasswordByEmailRow
	err := row.Scan(&i.ID, &i.Email)
	return i, err
}
