// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.26.0
// source: queries.sql

package db

import (
	"context"
	"database/sql"
)

const createCourse = `-- name: CreateCourse :execresult
INSERT INTO course (
  title, dept_id
) VALUES (
  ?, ?
)
`

type CreateCourseParams struct {
	Title  string
	DeptID sql.NullInt32
}

func (q *Queries) CreateCourse(ctx context.Context, arg CreateCourseParams) (sql.Result, error) {
	return q.db.ExecContext(ctx, createCourse, arg.Title, arg.DeptID)
}

const createDepartment = `-- name: CreateDepartment :execresult
INSERT INTO department (
  name
) VALUES (
  ?
)
`

func (q *Queries) CreateDepartment(ctx context.Context, name string) (sql.Result, error) {
	return q.db.ExecContext(ctx, createDepartment, name)
}

const createInstructor = `-- name: CreateInstructor :execresult
INSERT INTO instructor (
  name, dept_id
) VALUES (
  ?, ?
)
`

type CreateInstructorParams struct {
	Name   string
	DeptID sql.NullInt32
}

func (q *Queries) CreateInstructor(ctx context.Context, arg CreateInstructorParams) (sql.Result, error) {
	return q.db.ExecContext(ctx, createInstructor, arg.Name, arg.DeptID)
}

const createStudent = `-- name: CreateStudent :execresult
INSERT INTO student (
  name, dept_id
) VALUES (
  ?, ?
)
`

type CreateStudentParams struct {
	Name   string
	DeptID sql.NullInt32
}

func (q *Queries) CreateStudent(ctx context.Context, arg CreateStudentParams) (sql.Result, error) {
	return q.db.ExecContext(ctx, createStudent, arg.Name, arg.DeptID)
}

const deleteCourse = `-- name: DeleteCourse :exec
DELETE FROM course 
WHERE id = ?
`

func (q *Queries) DeleteCourse(ctx context.Context, id int32) error {
	_, err := q.db.ExecContext(ctx, deleteCourse, id)
	return err
}

const deleteEnrollmentByCourseID = `-- name: DeleteEnrollmentByCourseID :exec
DELETE FROM enrollment 
WHERE course_id = ?
`

func (q *Queries) DeleteEnrollmentByCourseID(ctx context.Context, courseID sql.NullInt32) error {
	_, err := q.db.ExecContext(ctx, deleteEnrollmentByCourseID, courseID)
	return err
}

const deleteStudent = `-- name: DeleteStudent :exec
DELETE FROM student 
WHERE id = ?
`

func (q *Queries) DeleteStudent(ctx context.Context, id int32) error {
	_, err := q.db.ExecContext(ctx, deleteStudent, id)
	return err
}

const enrollStudent = `-- name: EnrollStudent :execresult
INSERT INTO enrollment (
  student_id, course_id, semester, year
) VALUES (
  ?, ?, ?, ?
)
`

type EnrollStudentParams struct {
	StudentID sql.NullInt32
	CourseID  sql.NullInt32
	Semester  string
	Year      int32
}

func (q *Queries) EnrollStudent(ctx context.Context, arg EnrollStudentParams) (sql.Result, error) {
	return q.db.ExecContext(ctx, enrollStudent,
		arg.StudentID,
		arg.CourseID,
		arg.Semester,
		arg.Year,
	)
}

const getCoursesByDept = `-- name: GetCoursesByDept :many
SELECT id, title, dept_id FROM course WHERE dept_id = ?
`

func (q *Queries) GetCoursesByDept(ctx context.Context, deptID sql.NullInt32) ([]Course, error) {
	rows, err := q.db.QueryContext(ctx, getCoursesByDept, deptID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []Course
	for rows.Next() {
		var i Course
		if err := rows.Scan(&i.ID, &i.Title, &i.DeptID); 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 getDepartments = `-- name: GetDepartments :many
SELECT id, name FROM department
`

func (q *Queries) GetDepartments(ctx context.Context) ([]Department, error) {
	rows, err := q.db.QueryContext(ctx, getDepartments)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []Department
	for rows.Next() {
		var i Department
		if err := rows.Scan(&i.ID, &i.Name); 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 getEnrollmentByStudent = `-- name: GetEnrollmentByStudent :many
SELECT student_id, course_id, semester, year FROM enrollment WHERE student_id = ?
`

func (q *Queries) GetEnrollmentByStudent(ctx context.Context, studentID sql.NullInt32) ([]Enrollment, error) {
	rows, err := q.db.QueryContext(ctx, getEnrollmentByStudent, studentID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []Enrollment
	for rows.Next() {
		var i Enrollment
		if err := rows.Scan(
			&i.StudentID,
			&i.CourseID,
			&i.Semester,
			&i.Year,
		); 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 getInstructors = `-- name: GetInstructors :many
SELECT id, name, dept_id FROM instructor
`

func (q *Queries) GetInstructors(ctx context.Context) ([]Instructor, error) {
	rows, err := q.db.QueryContext(ctx, getInstructors)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []Instructor
	for rows.Next() {
		var i Instructor
		if err := rows.Scan(&i.ID, &i.Name, &i.DeptID); 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 getStudents = `-- name: GetStudents :many
SELECT id, name, dept_id FROM student
`

func (q *Queries) GetStudents(ctx context.Context) ([]Student, error) {
	rows, err := q.db.QueryContext(ctx, getStudents)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []Student
	for rows.Next() {
		var i Student
		if err := rows.Scan(&i.ID, &i.Name, &i.DeptID); 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 updateCourseTitle = `-- name: UpdateCourseTitle :exec
UPDATE course SET title = ?
WHERE id = ?
`

type UpdateCourseTitleParams struct {
	Title string
	ID    int32
}

func (q *Queries) UpdateCourseTitle(ctx context.Context, arg UpdateCourseTitleParams) error {
	_, err := q.db.ExecContext(ctx, updateCourseTitle, arg.Title, arg.ID)
	return err
}

const updateStudentName = `-- name: UpdateStudentName :exec
UPDATE student SET name = ?
WHERE id = ?
`

type UpdateStudentNameParams struct {
	Name string
	ID   int32
}

func (q *Queries) UpdateStudentName(ctx context.Context, arg UpdateStudentNameParams) error {
	_, err := q.db.ExecContext(ctx, updateStudentName, arg.Name, arg.ID)
	return err
}
