// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.20.0
// source: projects.sql

package db

import (
	"context"
	"database/sql"
)

const createProject = `-- name: CreateProject :one
insert into projects (name, description, created_by)
values (?, ?, ?)
returning id, name, description, created_by, created_at
`

type CreateProjectParams struct {
	Name        string
	Description sql.NullString
	CreatedBy   int64
}

func (q *Queries) CreateProject(ctx context.Context, arg CreateProjectParams) (Project, error) {
	row := q.db.QueryRowContext(ctx, createProject, arg.Name, arg.Description, arg.CreatedBy)
	var i Project
	err := row.Scan(
		&i.ID,
		&i.Name,
		&i.Description,
		&i.CreatedBy,
		&i.CreatedAt,
	)
	return i, err
}

const deleteProject = `-- name: DeleteProject :exec
delete from projects
where id = ?
`

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

const getProjectByID = `-- name: GetProjectByID :one
select id, name, description, created_by, created_at
from projects
where id = ?
`

func (q *Queries) GetProjectByID(ctx context.Context, id int64) (Project, error) {
	row := q.db.QueryRowContext(ctx, getProjectByID, id)
	var i Project
	err := row.Scan(
		&i.ID,
		&i.Name,
		&i.Description,
		&i.CreatedBy,
		&i.CreatedAt,
	)
	return i, err
}

const getProjectByName = `-- name: GetProjectByName :many
select id, name, description, created_by, created_at
from projects
where name = ?
  and created_by = ?
`

type GetProjectByNameParams struct {
	Name      string
	CreatedBy int64
}

func (q *Queries) GetProjectByName(ctx context.Context, arg GetProjectByNameParams) ([]Project, error) {
	rows, err := q.db.QueryContext(ctx, getProjectByName, arg.Name, arg.CreatedBy)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []Project
	for rows.Next() {
		var i Project
		if err := rows.Scan(
			&i.ID,
			&i.Name,
			&i.Description,
			&i.CreatedBy,
			&i.CreatedAt,
		); 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 getProjectsByUser = `-- name: GetProjectsByUser :many
select id, name, description, created_by, created_at
from projects
where created_by = ?
`

func (q *Queries) GetProjectsByUser(ctx context.Context, createdBy int64) ([]Project, error) {
	rows, err := q.db.QueryContext(ctx, getProjectsByUser, createdBy)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []Project
	for rows.Next() {
		var i Project
		if err := rows.Scan(
			&i.ID,
			&i.Name,
			&i.Description,
			&i.CreatedBy,
			&i.CreatedAt,
		); 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 updateProject = `-- name: UpdateProject :one
update projects
set name        = ?,
    description = ?
where id = ?
returning id, name, description, created_by, created_at
`

type UpdateProjectParams struct {
	Name        string
	Description sql.NullString
	ID          int64
}

func (q *Queries) UpdateProject(ctx context.Context, arg UpdateProjectParams) (Project, error) {
	row := q.db.QueryRowContext(ctx, updateProject, arg.Name, arg.Description, arg.ID)
	var i Project
	err := row.Scan(
		&i.ID,
		&i.Name,
		&i.Description,
		&i.CreatedBy,
		&i.CreatedAt,
	)
	return i, err
}
