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

package querier

import (
	"context"
)

const createUser = `-- name: CreateUser :one
INSERT INTO anclax.users (
    name,
    password_hash,
    password_salt
) VALUES (
    $1, $2, $3
) RETURNING id, name, password_hash, password_salt, created_at, updated_at, deleted_at
`

type CreateUserParams struct {
	Name         string
	PasswordHash string
	PasswordSalt string
}

func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (*AnclaxUser, error) {
	row := q.db.QueryRow(ctx, createUser, arg.Name, arg.PasswordHash, arg.PasswordSalt)
	var i AnclaxUser
	err := row.Scan(
		&i.ID,
		&i.Name,
		&i.PasswordHash,
		&i.PasswordSalt,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.DeletedAt,
	)
	return &i, err
}

const deleteUserByName = `-- name: DeleteUserByName :exec
UPDATE anclax.users SET deleted_at = CURRENT_TIMESTAMP WHERE name = $1
`

func (q *Queries) DeleteUserByName(ctx context.Context, name string) error {
	_, err := q.db.Exec(ctx, deleteUserByName, name)
	return err
}

const getUser = `-- name: GetUser :one
SELECT id, name, password_hash, password_salt, created_at, updated_at, deleted_at FROM anclax.users
WHERE id = $1 AND deleted_at IS NULL
`

func (q *Queries) GetUser(ctx context.Context, id int32) (*AnclaxUser, error) {
	row := q.db.QueryRow(ctx, getUser, id)
	var i AnclaxUser
	err := row.Scan(
		&i.ID,
		&i.Name,
		&i.PasswordHash,
		&i.PasswordSalt,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.DeletedAt,
	)
	return &i, err
}

const getUserByName = `-- name: GetUserByName :one
SELECT id, name, password_hash, password_salt, created_at, updated_at, deleted_at FROM anclax.users WHERE name = $1 AND deleted_at IS NULL
`

func (q *Queries) GetUserByName(ctx context.Context, name string) (*AnclaxUser, error) {
	row := q.db.QueryRow(ctx, getUserByName, name)
	var i AnclaxUser
	err := row.Scan(
		&i.ID,
		&i.Name,
		&i.PasswordHash,
		&i.PasswordSalt,
		&i.CreatedAt,
		&i.UpdatedAt,
		&i.DeletedAt,
	)
	return &i, err
}

const getUserDefaultOrg = `-- name: GetUserDefaultOrg :one
SELECT org_id FROM anclax.user_default_orgs
WHERE user_id = $1
`

func (q *Queries) GetUserDefaultOrg(ctx context.Context, userID int32) (int32, error) {
	row := q.db.QueryRow(ctx, getUserDefaultOrg, userID)
	var org_id int32
	err := row.Scan(&org_id)
	return org_id, err
}

const isUsernameExists = `-- name: IsUsernameExists :one
SELECT EXISTS (SELECT 1 FROM anclax.users WHERE name = $1)
`

func (q *Queries) IsUsernameExists(ctx context.Context, name string) (bool, error) {
	row := q.db.QueryRow(ctx, isUsernameExists, name)
	var exists bool
	err := row.Scan(&exists)
	return exists, err
}

const restoreUserByName = `-- name: RestoreUserByName :exec
UPDATE anclax.users SET deleted_at = NULL WHERE name = $1
`

func (q *Queries) RestoreUserByName(ctx context.Context, name string) error {
	_, err := q.db.Exec(ctx, restoreUserByName, name)
	return err
}

const setUserDefaultOrg = `-- name: SetUserDefaultOrg :exec
INSERT INTO anclax.user_default_orgs (user_id, org_id)
VALUES ($1, $2)
ON CONFLICT (user_id) DO UPDATE SET org_id = $2
`

type SetUserDefaultOrgParams struct {
	UserID int32
	OrgID  int32
}

func (q *Queries) SetUserDefaultOrg(ctx context.Context, arg SetUserDefaultOrgParams) error {
	_, err := q.db.Exec(ctx, setUserDefaultOrg, arg.UserID, arg.OrgID)
	return err
}

const updateUserPassword = `-- name: UpdateUserPassword :exec
UPDATE anclax.users SET password_hash = $2, password_salt = $3 WHERE id = $1
`

type UpdateUserPasswordParams struct {
	ID           int32
	PasswordHash string
	PasswordSalt string
}

func (q *Queries) UpdateUserPassword(ctx context.Context, arg UpdateUserPasswordParams) error {
	_, err := q.db.Exec(ctx, updateUserPassword, arg.ID, arg.PasswordHash, arg.PasswordSalt)
	return err
}
