// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.30.0
// source: learning_tree.sql

package dbgen

import (
	"context"

	"github.com/jackc/pgx/v5/pgtype"
)

const GetFullLearningTree = `-- name: GetFullLearningTree :many
SELECT
    c.id AS course_id,
    c.title AS course_title,
    sc.id AS sub_course_id,
    sc.title AS sub_course_title,
    sc.level AS sub_course_level
FROM courses c
LEFT JOIN sub_courses sc ON sc.course_id = c.id AND sc.is_active = true
WHERE c.is_active = true
ORDER BY c.id, sc.display_order, sc.id
`

type GetFullLearningTreeRow struct {
	CourseID       int64       `json:"course_id"`
	CourseTitle    string      `json:"course_title"`
	SubCourseID    pgtype.Int8 `json:"sub_course_id"`
	SubCourseTitle pgtype.Text `json:"sub_course_title"`
	SubCourseLevel pgtype.Text `json:"sub_course_level"`
}

func (q *Queries) GetFullLearningTree(ctx context.Context) ([]GetFullLearningTreeRow, error) {
	rows, err := q.db.Query(ctx, GetFullLearningTree)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var items []GetFullLearningTreeRow
	for rows.Next() {
		var i GetFullLearningTreeRow
		if err := rows.Scan(
			&i.CourseID,
			&i.CourseTitle,
			&i.SubCourseID,
			&i.SubCourseTitle,
			&i.SubCourseLevel,
		); err != nil {
			return nil, err
		}
		items = append(items, i)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}
	return items, nil
}
