import directus from "./directus";
import { readItems } from "@directus/sdk";

export const courses = await directus.request(
    readItems("codyops_courses", {
        fields: [
            '*',
            'user_created.*',
            'modules.*'
        ]}
    )
);

export function getAllCourses() {
    return courses;
};

export function getUniqueCategories(courses: any ) {
    const allCategories = courses.flatMap((course: any) => course.category);
    const uniqueCategories = [...new Set(allCategories)];
    return uniqueCategories;
};

export function filterCoursesByCategory(courses: any, category: any) {
    return courses.filter((course: any) => course.category.includes(category));
};

export function filterCoursesByCloud(courses: any, clouds: string[]) {
    return courses.filter((course: any) => course.cloud?.includes(clouds));
};

