# seed_reading_questions.py

from django.core.management.base import BaseCommand
from toefl_prep_app.models import Question, Choice, CorrectAnswer
from django.core.files import File
import os

class Command(BaseCommand):
    help = 'Seed reading questions and choices data'

    def handle(self, *args, **kwargs):
        # Sample data for reading questions and choices
        reading_questions_data = [
            {
                'passage_image_path': 'audio/passage1.png',  # Path to passage image file
                'question_text': 'Which of the following is the main topic of passage?',
                'choices': ['Assessment of the work of specialist concerned with ecology', 'A discussion of possible causes of extinction, and of ways to make predictions about environmental change', 'The changing aspects of our environment', 'A comparison of the extinction rates of different taxa'],
                'correct_choice_index': 1  # Index of correct choice in choices list
            },
            {
                'passage_image_path': 'audio/passage1.png',  # Path to passage image file
                'question_text': 'The word susceptibility in line 3 is closest in meaning to…',
                'choices': ['insensitivity', 'receptiveness', 'immunity', 'vulnerability'],
                'correct_choice_index': 3  # Index of correct choice in choices list
            },
            {
                'passage_image_path': 'audio/passage1.png',  # Path to passage image file
                'question_text': 'An example of a taxon would be…',
                'choices': ['a phylum', 'the rate of environmental of change', 'a fossil', 'studies of extinction'],
                'correct_choice_index': 0  # Index of correct choice in choices list
            },
            {
                'passage_image_path': 'audio/passage1.png',  # Path to passage image file
                'question_text': 'The Author compares mammals and birds to…',
                'choices': ['Mollusks and insects', 'Phylum and class', 'Dinosaurs and reptiles', 'Ecologists and biologists'],
                'correct_choice_index': 0  # Index of correct choice in choices list
            },
            {
                'passage_image_path': 'audio/passage1.png',  # Path to passage image file
                'question_text': 'It can be inferred from the passage that a significant event of the Crustaceous period was…',
                'choices': ['The appearance of many taxa', 'The dramatic, effect of the dinosaur on the environment', 'The extinction of birds', 'The extinction of dinosaurs'],
                'correct_choice_index': 3  # Index of correct choice in choices list
            },
            {
                'passage_image_path': 'audio/passage1.png',  # Path to passage image file
                'question_text': 'It can be inferred from the passage that dinosaurs…',
                'choices': ['Included species that were mammals', 'Were better represented in the fossil record than other species', 'Possessed disadvantageous traits', 'Were not susceptible to extinction'],
                'correct_choice_index': 2  # Index of correct choice in choices list
            },
            {
                'passage_image_path': 'audio/passage1.png',  # Path to passage image file
                'question_text': 'The word dramatically in line 10 means…',
                'choices': ['strongly', 'inspiringly', 'flimsily', 'visually'],
                'correct_choice_index': 0  # Index of correct choice in choices list
            },
            {
                'passage_image_path': 'audio/passage1.png',  # Path to passage image file
                'question_text': 'The word fields in line 12 is closest in meaning to…',
                'choices': ['areas', 'meadows', 'studies', 'careers'],
                'correct_choice_index': 2  # Index of correct choice in choices list
            },
            {
                'passage_image_path': 'audio/passage1.png',  # Path to passage image file
                'question_text': 'From the passage it can be inferred the disadvantageous traits are…',
                'choices': ['occurring at different rates', 'a contributing cause of extinction', 'adaptable', 'learned by mathematical formulas'],
                'correct_choice_index': 1  # Index of correct choice in choices list
            },
            {
                'passage_image_path': 'audio/passage1.png',  # Path to passage image file
                'question_text': 'The expression singled out in lines 16 is closest is meaning to…',
                'choices': ['isolated', 'blamed', 'seen', 'divided'],
                'correct_choice_index': 0  # Index of correct choice in choices list
            },            
            {
                'passage_image_path': 'audio/passage1.png',  # Path to passage image file
                'question_text': 'According to the passage, the likelihood of a population becoming extinct can be…',
                'choices': ['Lessened by the efforts of a few concerned specialists', 'Unaffected by environmental change', 'Determined by mathematical formulas', 'Almost impossible to ascertain'],
                'correct_choice_index': 2  # Index of correct choice in choices list
            },            
            {
                'passage_image_path': 'audio/passage1.png',  # Path to passage image file
                'question_text': 'The word broader in line 23 is closest in meaning to…',
                'choices': ['fatter', 'extra', 'wider', 'many'],
                'correct_choice_index': 2  # Index of correct choice in choices list
            },            
            {
                'passage_image_path': 'audio/passage2.png',  # Path to passage image file
                'question_text': 'In which of the following publications would this passage the most likely to appear?',
                'choices': ['An anthology of English literature', 'An introductory American history book', 'A book about Eastern religions', 'A basic math textbook'],
                'correct_choice_index': 1  # Index of correct choice in choices list
            },            
            {
                'passage_image_path': 'audio/passage2.png',  # Path to passage image file
                'question_text': 'The word their in line 4 refers to…',
                'choices': ['trappings', 'preachers', 'Religious services', 'The Friends'],
                'correct_choice_index': 3  # Index of correct choice in choices list
            },            
            {
                'passage_image_path': 'audio/passage2.png',  # Path to passage image file
                'question_text': 'The word persecuted in lines 8 is closest in meaning to…',
                'choices': ['scrutinized', 'Lauded', 'harassed', 'believed'],
                'correct_choice_index': 2  # Index of correct choice in choices list
            },            
            {
                'passage_image_path': 'audio/passage2.png',  # Path to passage image file
                'question_text': 'Where in the passage does the author give an example of Quaker involvement in social issues…',
                'choices': ['Lines 4-5', 'Lines 11-12', 'Lines 13-14', 'Lines 16-17'],
                'correct_choice_index': 3  # Index of correct choice in choices list
            },            
            {
                'passage_image_path': 'audio/passage2.png',  # Path to passage image file
                'question_text': 'Which of the following would be an example of “the outward trappings associated with Christianity” referred to in lines 6?',
                'choices': ['clergy', 'silent, leaderless worship', 'concern for social reform', 'the doctrine of “God in every man”'],
                'correct_choice_index': 0  # Index of correct choice in choices list
            },            
            {
                'passage_image_path': 'audio/passage2.png',  # Path to passage image file
                'question_text': 'It can be inferred from the passage that early Quakers experienced official persecution because…',
                'choices': ['They were known for “quaking” during religious services', 'They helped found the state of Pennsylvania', 'They came to America from England', 'Their religious beliefs were considered subversive '],
                'correct_choice_index': 3  # Index of correct choice in choices list
            },            
            {
                'passage_image_path': 'audio/passage2.png',  # Path to passage image file
                'question_text': 'Why does the author mention execution in lines 9?',
                'choices': ['It is an example of the persecution Quakers faced', 'It is an outward trapping of Christianity', 'This serves as an example of William Penn’s policies', 'Many religions were concerned with this issue'],
                'correct_choice_index': 0  # Index of correct choice in choices list
            },            
            {
                'passage_image_path': 'audio/passage2.png',  # Path to passage image file
                'question_text': 'The paragraph after this passage would most likely be about…',
                'choices': ['The decline of the Quaker population since World War I', 'The similarities and differences between Quakers and Puritans', 'Ways in which Quakers today show concern for others', 'Social reforms enacted by Quakers during the American Revolution'],
                'correct_choice_index': 2  # Index of correct choice in choices list
            },                        
            {
                'passage_image_path': 'audio/passage2.png',  # Path to passage image file
                'question_text': 'From the passage, it can be inferred that the Puritans were…',
                'choices': ['friends', 'persecuted', 'intolerant', 'Executed'],
                'correct_choice_index': 2  # Index of correct choice in choices list
            },                        
            {
                'passage_image_path': 'audio/passage2.png',  # Path to passage image file
                'question_text': 'The word penchant in line 10 most nearly means…',
                'choices': ['Appreciation', 'Propensity', 'Disinclination', 'Proposition'],
                'correct_choice_index': 1  # Index of correct choice in choices list
            },                        
            {
                'passage_image_path': 'audio/passage2.png',  # Path to passage image file
                'question_text': 'Why did the American Quaker population surge after William Penn founded Pennsylvania?',
                'choices': ['Pennsylvania tolerated the Quaker religion', 'Pennsylvania forbade religions other than Quakerism', 'The Pennsylvania government tried to help escaped slaves', 'Social reform was important to most Americans'],
                'correct_choice_index': 0  # Index of correct choice in choices list
            },                        
            {
                'passage_image_path': 'audio/passage3.png',  # Path to passage image file
                'question_text': 'The degree of viscosity in newly issued lava is a critical determinant of…',
                'choices': ['The chemical nature of the magma', 'Whether the lava will be red or white hot', 'The ultimate nature of the hardened lava field', 'The viscosity of the liquid rock'],
                'correct_choice_index': 2  # Index of correct choice in choices list
            },                        
            {
                'passage_image_path': 'audio/passage3.png',  # Path to passage image file
                'question_text': 'The chemical composition of a hardened field…',
                'choices': ['Has nothing to do with the viscosity of the liquid rock', 'Will cause the crusting phenomena common in hardened lava', 'Is important in shaping the ultimate appearance of the field', 'Depends upon the degree of viscosity of the original liquid rock'],
                'correct_choice_index': 2  # Index of correct choice in choices list
            },                        
            {
                'passage_image_path': 'audio/passage3.png',  # Path to passage image file
                'question_text': 'In line 10, the word issues most nearly means…',
                'choices': ['Is dormant', 'Heats up', 'traverses', 'comes out'],
                'correct_choice_index': 3  # Index of correct choice in choices list
            },                        
            {
                'passage_image_path': 'audio/passage3.png',  # Path to passage image file
                'question_text': 'Knots of surface rocks are characteristic of…',
                'choices': ['All types of ultimate lava fields', 'The initial stage of some lava field formation', 'The end result of some highly viscous flows', 'Only highly liquid, wavelike lava forms'],
                'correct_choice_index': 2  # Index of correct choice in choices list
            },                        
            {
                'passage_image_path': 'audio/passage3.png',  # Path to passage image file
                'question_text': 'If the hardened lava presents a smoother wavelike surface it is likely that…',
                'choices': ['It was not initially a highly liquid lava', 'It results from a highly liquid lava', 'Its final form will be rough and difficult to traverse', 'At issue, it was red-hot'],
                'correct_choice_index': 1  # Index of correct choice in choices list
            },                        
            {
                'passage_image_path': 'audio/passage3.png',  # Path to passage image file
                'question_text': 'The primary function of this passage is to…',
                'choices': ['Explain the primary chemical of lava, including silica and oxides', 'Predict when volcanic lava will appear', 'Warn of the limitations of viscosity and chemical analysis', 'Discuss two crucial determinants of a hardened lava field’s character'],
                'correct_choice_index': 3  # Index of correct choice in choices list
            },                        
            {
                'passage_image_path': 'audio/passage3.png',  # Path to passage image file
                'question_text': 'The word exhibit in line 15 is closest in meaning to…',
                'choices': ['Give off', 'Put on', 'Show', 'Cause'],
                'correct_choice_index': 2  # Index of correct choice in choices list
            },                        
            {
                'passage_image_path': 'audio/passage3.png',  # Path to passage image file
                'question_text': 'This passage would most likely appear in which type of publication?',
                'choices': ['An introductory college textbook on geography', 'The national events section of a local newspaper', 'An introductory college textbook on geology', 'A tourist brochure for a volcanic region'],
                'correct_choice_index': 2  # Index of correct choice in choices list
            },
            {
                'passage_image_path': 'audio/passage4.png',  # Path to passage image file
                'question_text': 'Which of the following is the most appropriate title for the passage?',
                'choices': ['A revolution in fashion', 'Clothing shortages of the revolution', 'Clothing styles in revolutionary America', 'Conflict in the Fashion Industry'],
                'correct_choice_index': 2  # Index of correct choice in choices list
            },        
            {
                'passage_image_path': 'audio/passage4.png',  # Path to passage image file
                'question_text': 'The word “beau” in line 3 is closest in meaning to…',
                'choices': ['Male friend', 'Husband', 'Father', 'Son'],
                'correct_choice_index': 0  # Index of correct choice in choices list
            },
            {
                'passage_image_path': 'audio/passage4.png',  # Path to passage image file
                'question_text': 'Which of the following can be inferred from the passage about people’s attitudes toward fashion?',
                'choices': ['They varied according to political beliefs', 'They were determined mainly by geography', 'They corresponded to a persons social standing', 'They were a matter of personal taste'],
                'correct_choice_index': 0  # Index of correct choice in choices list
            },            
            {
                'passage_image_path': 'audio/passage4.png',  # Path to passage image file
                'question_text': 'The word “loomed” in line 5 is closest in meaning to…',
                'choices': ['Grew bigger', 'wove', 'picked', 'quilted'],
                'correct_choice_index': 1  # Index of correct choice in choices list
            },
            {
                'passage_image_path': 'audio/passage4.png',  # Path to passage image file
                'question_text': 'What were clothes made from in rural areas?',
                'choices': ['Home made wool', 'Imported British goods', 'Cloth stolen from the British', 'Gauze'],
                'correct_choice_index': 0  # Index of correct choice in choices list
            },
            {
                'passage_image_path': 'audio/passage4.png',  # Path to passage image file
                'question_text': '“Fashion babies” were…',
                'choices': ['Dolls for children', '12-inches figures used to display clothes', 'Life-sized models dressed in current styles', 'Illustrations from fashion magazines'],
                'correct_choice_index': 1  # Index of correct choice in choices list
            },
            {
                'passage_image_path': 'audio/passage4.png',  # Path to passage image file
                'question_text': 'The word “tyranny” in line 9 is closest in meaning to…',
                'choices': ['Domination', 'Bossiness', 'Importance', 'Evilness'],
                'correct_choice_index': 0  # Index of correct choice in choices list
            },
            {
                'passage_image_path': 'audio/passage4.png',  # Path to passage image file
                'question_text': 'Which of the following can best be said about the Paris fashion industry?',
                'choices': ['It has come to the forefront only recent compared to New York', 'It has long exerted a powerful influence or American fashion', 'It retains its taste for gaudy, “macaroni” type excess', 'It is unable to break free from New York’s influence'],
                'correct_choice_index': 1  # Index of correct choice in choices list
            },
            {
                'passage_image_path': 'audio/passage4.png',  # Path to passage image file
                'question_text': 'Black armbands were worn to show…',
                'choices': ['the tyranny of Paris fashions', 'imported cloth from England', 'fanciful detailing', 'mourning'],
                'correct_choice_index': 3  # Index of correct choice in choices list
            },
            {
                'passage_image_path': 'audio/passage4.png',  # Path to passage image file
                'question_text': 'The word “elaborate” in line 13 is closest in meaning to…',
                'choices': ['Gay', 'vulgar', 'Intricate', 'square'],
                'correct_choice_index': 2  # Index of correct choice in choices list
            },
            {
                'passage_image_path': 'audio/passage4.png',  # Path to passage image file
                'question_text': 'It can be inferred from the passage that “macaroni”…',
                'choices': ['Was so named because of its resemblance to the continent of Europe', 'Was a very short-lived and ill-conceived fashion trend', 'Had a more mundane application to petticoats and aprons', 'Was not the fashion style of avowed patriots'],
                'correct_choice_index': 3  # Index of correct choice in choices list
            },
            {
                'passage_image_path': 'audio/passage5.png',  # Path to passage image file
                'question_text': 'What is the main topic of this passage?',
                'choices': ["Cather’s anti-slavery stance", "The backdrop of Cather’s last novel", "Cather’s strangely titled novel", "Life in The Virginia country"],
                'correct_choice_index': 1  # Index of correct choice in choices list
            },
            {
                'passage_image_path': 'audio/passage5.png',  # Path to passage image file
                'question_text': 'The author refers to Sapphira and the Slave Girl as…',
                'choices': ["A heroic tale of the Civil war", "A sweeping epic of the Old South", "Using Cather’s personal recollections", "A political treatise on slavery"],
                'correct_choice_index': 2  # Index of correct choice in choices list
            },
            {
                'passage_image_path': 'audio/passage5.png',  # Path to passage image file
                'question_text': 'The word vivid in line 2 is closest in meaning to…',
                'choices': ['Disturbing', 'Buried', 'forgotten', 'clear'],
                'correct_choice_index': 3  # Index of correct choice in choices list
            },
            {
                'passage_image_path': 'audio/passage5.png',  # Path to passage image file
                'question_text': 'What is NOT true of Mandy Ringer?',
                'choices': ['She is a slave', 'She is intelligent', 'She is uneducated', 'She is poor'],
                'correct_choice_index': 0  # Index of correct choice in choices list
            },
            {
                'passage_image_path': 'audio/passage5.png',  # Path to passage image file
                'question_text': 'In the second paragraph, the author mentions Mandy Ringer in order to emphasize which point?',
                'choices': ["The novel displays Cather’s mixed feelings about slavery", "The characters are based on Gather’s childhood friends", "One of the novel’s purposes was to paint a portrait of life in nineteenth-century rural Virginia", "The novel’s characters are shown in a positive light because Gather was a supporter of the Old South"],
                'correct_choice_index': 2  # Index of correct choice in choices list
            },
            {
                'passage_image_path': 'audio/passage5.png',  # Path to passage image file
                'question_text': 'According to the author, what is Cather’s attitude toward slavery somewhat ambiguous?',
                'choices': ['She was knowledgeable about the legal and political aspects of slavery', 'She did not denounce slavery directly, only in indirect ways', 'She identified equally with slaves and slaveholders', 'She was unable to fashion a firm opinion on the issue'],
                'correct_choice_index': 1  # Index of correct choice in choices list
            },
            {
                'passage_image_path': 'audio/passage5.png',  # Path to passage image file
                'question_text': 'One can infer that the author would probably…',
                'choices': ["Like Gather if the author met her", "Consider the character of Mandy Ringer irrelevant to the plot", "Oppose the academic study Cather’s other novels", "Have no appreciation of the Novel’s merits"],
                'correct_choice_index': 1  # Index of correct choice in choices list
            },
            {
                'passage_image_path': 'audio/passage5.png',  # Path to passage image file
                'question_text': 'Which of the following would be the best title for the passage?',
                'choices': ["Sapphira and the Salve Girl Fact Versus Fiction", "Willa Cather : Racist or Abolitionist?", "Some Comments on the Final Novel of Willa Cather", "Willa Cather’s Depiction of Nineteenth-Century Virginians"],
                'correct_choice_index': 2  # Index of correct choice in choices list
            },
            # Add more reading question data here
        ]

        for question_data in reading_questions_data:
            # Create Question instance with passage image
            passage_image_path = question_data['passage_image_path']
            if os.path.exists(passage_image_path):
                with open(passage_image_path, 'rb') as f:
                    passage_image = File(f)
                    question = Question.objects.create(question_text=question_data['question_text'], passage=passage_image)
            else:
                self.stdout.write(self.style.ERROR(f'Passage image not found at {passage_image_path}. Skipping question.'))

            # Create choices for the reading question
            for choice_text in question_data['choices']:
                choice = Choice.objects.create(question=question, choice_text=choice_text)

            # Set the correct answer for the reading question
            correct_choice_index = question_data['correct_choice_index']
            correct_choice = Choice.objects.filter(question=question)[correct_choice_index]

            # Create CorrectAnswer instance and associate it with the reading question
            correct_answer = CorrectAnswer.objects.create(question=question, correct_choice=correct_choice)

        self.stdout.write(self.style.SUCCESS('Reading questions and choices seeded successfully.'))