def write(self, lesson):

        try:
            with FileWriter.open(self.filePath) as file:
                lessonSummary = lesson.prepareSummaryAsWritableFormat()
                file.write(lessonSummary)
                newLessonOffSetValue = len(lessonSummary)
                self.lessonFileIndex[lesson.code] = newLessonOffSetValue
                print("Ders başarıyla kaydedildi.")
        except Exception as e:
            print(f"Hata: {e}")
 def write(self, student):
     
     if student is None:
         return
     
     try:
         with FileWriter.open(self.filePath) as file:
             studentSummary = student.prepareSummaryAsWritableFormat()
             file.write(studentSummary)
             newStudentOffSetValue = len(studentSummary)
             self.studentFileIndex[student.no] = newStudentOffSetValue
             print("Öğrenci başarıyla kaydedildi.")
     except Exception as e:
         print(f"Hata: {e}")
    def update(self, no):

        if no < 0:
            print("Record is not a student!")
            return

        seekSummary = SeekOffsetCalculator.determineSeekValueAndOffset(self.studentFileIndex, no)
        jumpToSeekValue = seekSummary["jumpToSeekValue"]
        currentStudentOffset = seekSummary["currentRecordOffset"]

        firstPartLines = []
        lastPartLines = []
        with FileReader.open(self.filePath) as file:
            file.seek(0)
            firstPartLines = file.read(jumpToSeekValue).splitlines()
            print(firstPartLines)
            file.seek(currentStudentOffset + jumpToSeekValue)
            lastPartLines = file.read().splitlines()
            print(lastPartLines)


        with FileWriter.reset(self.filePath) as file:
            file.seek(0)
            if len(firstPartLines) > 0:
                content = ""
                for line in firstPartLines:
                    content += line + "\n"
                file.writelines(content)


        with FileWriter.update(self.filePath) as file:
            file.seek(jumpToSeekValue)
            student = StudentRecorder.create()
            studentSummary = student.prepareSummaryAsWritableFormat()
            file.write(studentSummary)
            newStudentOffSetValue = len(studentSummary)
            self.studentFileIndex[student.no] = newStudentOffSetValue
            print("Öğrenci başarıyla güncellendi.")
        
        with FileWriter.open(self.filePath) as file:
            content = ""
            for line in lastPartLines:
                content += line + "\n"
            file.writelines(content)
    def update(self, code):

        print(self.lessonFileIndex)
        seekSummary = SeekOffsetCalculator.determineSeekValueAndOffset(
            self.lessonFileIndex, code)
        jumpToSeekValue = seekSummary["jumpToSeekValue"]
        currentLessonOffset = seekSummary["currentRecordOffset"]

        firstPartLines = []
        lastPartLines = []
        with FileReader.open(self.filePath) as file:
            file.seek(0)
            firstPartLines = file.read(jumpToSeekValue).splitlines()
            print(firstPartLines)
            file.seek(currentLessonOffset + jumpToSeekValue)
            lastPartLines = file.read().splitlines()
            print(lastPartLines)

        with FileWriter.reset(self.filePath) as file:
            file.seek(0)
            if len(firstPartLines) > 0:
                content = ""
                for line in firstPartLines:
                    content += line + "\n"
                file.writelines(content)

        with FileWriter.update(self.filePath) as file:
            file.seek(jumpToSeekValue)
            lesson = LessonRecorder.create()
            lessonSummary = lesson.prepareSummaryAsWritableFormat()
            file.write(lessonSummary)
            newLessonOffSetValue = len(lessonSummary)
            self.lessonFileIndex[lesson.code] = newLessonOffSetValue
            print("Ders başarıyla güncellendi.")

        with FileWriter.open(self.filePath) as file:
            content = ""
            for line in lastPartLines:
                content += line + "\n"
            file.writelines(content)