// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.25.0
// source: warehouse_worker.sql

package db

import (
	"context"
)

const deleteWarehouseWorker = `-- name: DeleteWarehouseWorker :exec
DELETE FROM warehouse_worker WHERE id = $1 AND user_id != $2
`

type DeleteWarehouseWorkerParams struct {
	ID     int64 `json:"id"`
	UserID int64 `json:"user_id"`
}

func (q *Queries) DeleteWarehouseWorker(ctx context.Context, arg DeleteWarehouseWorkerParams) error {
	_, err := q.db.Exec(ctx, deleteWarehouseWorker, arg.ID, arg.UserID)
	return err
}

const existsWarehouseWorker = `-- name: ExistsWarehouseWorker :one
SELECT EXISTS(
    SELECT 1 
    FROM warehouse_worker
    WHERE warehouse_id = $1 AND user_id = $2
)
`

type ExistsWarehouseWorkerParams struct {
	WarehouseID int64 `json:"warehouse_id"`
	UserID      int64 `json:"user_id"`
}

func (q *Queries) ExistsWarehouseWorker(ctx context.Context, arg ExistsWarehouseWorkerParams) (bool, error) {
	row := q.db.QueryRow(ctx, existsWarehouseWorker, arg.WarehouseID, arg.UserID)
	var exists bool
	err := row.Scan(&exists)
	return exists, err
}

const existsWarehouseWorkerByUsername = `-- name: ExistsWarehouseWorkerByUsername :one
SELECT EXISTS(
    SELECT 1 
    FROM warehouse_worker ww
    JOIN "user" u ON ww.user_id = u.id
    WHERE ww.warehouse_id = $1 AND u.username = $2
)
`

type ExistsWarehouseWorkerByUsernameParams struct {
	WarehouseID int64  `json:"warehouse_id"`
	Username    string `json:"username"`
}

func (q *Queries) ExistsWarehouseWorkerByUsername(ctx context.Context, arg ExistsWarehouseWorkerByUsernameParams) (bool, error) {
	row := q.db.QueryRow(ctx, existsWarehouseWorkerByUsername, arg.WarehouseID, arg.Username)
	var exists bool
	err := row.Scan(&exists)
	return exists, err
}

const getWarehouseWorkers = `-- name: GetWarehouseWorkers :many
SELECT ww.id, u.username
FROM warehouse_worker ww
JOIN "user" u ON ww.user_id = u.id
WHERE ww.warehouse_id = $1
`

type GetWarehouseWorkersRow struct {
	ID       int64  `json:"id"`
	Username string `json:"username"`
}

func (q *Queries) GetWarehouseWorkers(ctx context.Context, warehouseID int64) ([]GetWarehouseWorkersRow, error) {
	rows, err := q.db.Query(ctx, getWarehouseWorkers, warehouseID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []GetWarehouseWorkersRow
	for rows.Next() {
		var i GetWarehouseWorkersRow
		if err := rows.Scan(&i.ID, &i.Username); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}

const insertWarehouseWorker = `-- name: InsertWarehouseWorker :exec
INSERT INTO warehouse_worker (warehouse_id, user_id) VALUES ($1, $2)
`

type InsertWarehouseWorkerParams struct {
	WarehouseID int64 `json:"warehouse_id"`
	UserID      int64 `json:"user_id"`
}

func (q *Queries) InsertWarehouseWorker(ctx context.Context, arg InsertWarehouseWorkerParams) error {
	_, err := q.db.Exec(ctx, insertWarehouseWorker, arg.WarehouseID, arg.UserID)
	return err
}

const insertWarehouseWorkerByUsername = `-- name: InsertWarehouseWorkerByUsername :exec
INSERT INTO warehouse_worker (warehouse_id, user_id)
SELECT
    $1 AS warehouse_id,
    u.id AS user_id
FROM
    "user" u
WHERE
    u.username = $2
`

type InsertWarehouseWorkerByUsernameParams struct {
	WarehouseID int64  `json:"warehouse_id"`
	Username    string `json:"username"`
}

func (q *Queries) InsertWarehouseWorkerByUsername(ctx context.Context, arg InsertWarehouseWorkerByUsernameParams) error {
	_, err := q.db.Exec(ctx, insertWarehouseWorkerByUsername, arg.WarehouseID, arg.Username)
	return err
}
