import useAxios from "axios-hooks";

const useSampleApi = () => {
  const [{ ...getStudentsTestResultData }, getStudentsTestResult] = useAxios(
    {
      method: "GET",
    },
    {
      manual: true,
    }
  );

  const handleGetStudentsTestResult = async (activity_id, enterprise_id) => {
    try {
      const url = enterprise_id
        ? `/learn/v1/instructor/${enterprise_id}/tests/${activity_id}/submission_test_questions/`
        : `/learn/v1/instructor/tests/${activity_id}/submission_test_questions/`;
      await getStudentsTestResult({
        url,
      });
    } catch (err) {
      console.log(err);
    }
  };

  const [{ ...getStudentsTestAnswerData }, getStudentsAnser] = useAxios(
    {
      method: "GET",
    },
    {
      manual: true,
    }
  );

  const handleGetStudentsAnswer = async (
    question_activity_id,
    enterprise_id
  ) => {
    try {
      const url = `/learn/v2/instructor/${enterprise_id}/tests/question_activity/${question_activity_id}/`;
      await getStudentsAnser({
        url,
      });
    } catch (err) {
      console.log(err);
    }
  };

  return {
    handleGetStudentsTestResult,
    getStudentsTestResultData,
    handleGetStudentsAnswer,
    getStudentsTestAnswerData,
  };
};

export default useSampleApi;
