import { getRequest } from "@/api/customFetch";
import { getCourseDetail, getLessonCatalog, getLessonCategory, getLessonList } from "@/api/interfaceDocument";

export const useGetLessonCategory = () => {
    const lessonCategory = ref<any[]>([]);
    getRequest(getLessonCategory()).then(resp => {
        if(resp.code === 200){
            lessonCategory.value = (resp.result as {categories:any[]}).categories;
        }
    })

    return { lessonCategory }
}

export const useGetLessonList = () => {
    const lessonList = ref<any[]>([]);
    getRequest(getLessonList()).then(resp => {
        if(resp.code === 200){
            lessonList.value = (resp.result as {items:any[]}).items;
        }
    })

    return { lessonList }
}

export const useGetCourseDetail = () => {
    const courseDetail = ref<any>({});
    getRequest(getCourseDetail()).then(resp => {
        if(resp.code === 200){
            courseDetail.value = resp.result;
        }
    })

    return { courseDetail }
}

export const useGetCourseCatalog = () => {
    const courseCatalog = ref<any[]>([]);
    getRequest(getLessonCatalog()).then(resp => {
        if(resp.code === 200){
            courseCatalog.value = (resp.result as {chapters:any[]}).chapters;
        }
    })

    return { courseCatalog }
}