#!/usr/bin/env python
"""
Education Management Module for BaoLife

This module contains all education-related classes and functions including:
- School classes (Elementary, High School, College)
- Education record management
- Focus and extracurricular activities
- College major definitions

Classes:
    - ElementarySchoolClass: Elementary school location class
    - HighSchoolClass: High school location class
    - CollegeClass: College/university location class
    - CollegeMajorClass: College major definitions
    - FocusClass: Focus types for activities (Work Hard, Slack Off, etc.)
    - ExtraCurricular: Extracurricular activity definitions

Functions:
    - getSchools: Returns lists of elementary and high schools
    - getColleges: Returns list of colleges
    - getMajors: Returns list of college majors
    - getFocuses: Returns list of focus types
    - randomFocus: Returns random focus
    - update_focus: Updates focus for an activity
    - getFocus: Gets focus object by name
    - getExtraCurriculars: Returns list of extracurricular activities
    - randomExtraCurricular: Returns random extracurricular
    - setEducation: Sets up education for a person based on age
    - handleEducation: Handles GPA updates based on focus
    - setExtracurricular: Assigns extracurricular to person
    - applyForExtracurricular: Apply for an extracurricular activity
    - quitExtraCurricular: Quit an extracurricular activity
"""

import random
import uuid


# ============================================================
# Base Classes (imported from parent module)
# ============================================================
# These will be imported from functions.py:
# - locationClass
# - ActivityRecord
# - EducationRecord
# - getPeakEnergy


# ============================================================
# School Location Classes
# ============================================================

class ElementarySchoolClass:
    """
    Elementary School location class (inherits from locationClass)

    Attributes:
        id: Unique identifier
        type: Location type ('elementary_school')
        title: School name
        public_private: 'Public' or 'Private'
        student_count: Number of students
        teacher_student_ratio: Teacher to student ratio
        description: Generated description
        energyModifier: Energy cost (15)
        image: Optional image URL
    """
    def __init__(self, type, school_name, public_private, student_count, teacher_student_ratio, image=None):
        # Import here to avoid circular dependency
        from core.models import locationClass

        self.id = uuid.uuid4().hex
        # Initialize locationClass attributes
        locationClass.__init__(self, self.id, type, image)

        self.title = school_name
        self.public_private = public_private
        self.student_count = student_count
        self.teacher_student_ratio = teacher_student_ratio
        self.type = "elementary_school"
        self.description = "A " + self.public_private + " elementary school with " + str(self.student_count) + " students and a teacher-student ratio of " + str(self.teacher_student_ratio) + "."
        self.energyModifier = 15


class HighSchoolClass:
    """
    High School location class (inherits from locationClass)

    Attributes:
        id: Unique identifier
        type: Location type ('high_school')
        title: School name
        public_private: 'Public' or 'Private'
        student_count: Number of students
        teacher_student_ratio: Teacher to student ratio
        GPA_avg: Average GPA at the school
        description: Generated description
        energyModifier: Energy cost (20)
        image: Optional image URL
    """
    def __init__(self, type, school_name, public_private, student_count, teacher_student_ratio, GPA_avg, image=None):
        # Import here to avoid circular dependency
        from core.models import locationClass

        self.id = uuid.uuid4().hex
        # Initialize locationClass attributes
        locationClass.__init__(self, self.id, type, image)

        self.title = school_name
        self.public_private = public_private
        self.student_count = student_count
        self.teacher_student_ratio = teacher_student_ratio
        self.GPA_avg = GPA_avg
        self.type = "high_school"
        self.description = "A " + self.public_private + " high school with " + str(self.student_count) + " students, a teacher-student ratio of " + str(self.teacher_student_ratio) + ", and an average GPA of " + str(self.GPA_avg) + "."
        self.energyModifier = 20


class CollegeClass:
    """
    College/University location class (inherits from locationClass)

    Attributes:
        id: Unique identifier
        type: Location type ('college')
        title: College name
        public_private: 'Public' or 'Private'
        attendance: Number of students
        GPA_req: Required GPA for admission
        ACT_req: Required ACT score for admission
        specialization: Area of focus
        cost: Annual cost of attendance
        description: Generated description
        energyModifier: Energy cost (20)
        image: Optional image URL
    """
    def __init__(self, type, title, public_private, attendance, GPA_req, ACT_req, specialization, cost, image=None):
        # Import here to avoid circular dependency
        from core.models import locationClass

        self.id = uuid.uuid4().hex
        # Initialize locationClass attributes
        locationClass.__init__(self, self.id, type, image)

        self.title = title
        self.public_private = public_private
        self.attendance = attendance
        self.GPA_req = GPA_req
        self.ACT_req = ACT_req
        self.specialization = specialization
        self.cost = cost
        self.type = "college"
        self.description = "A " + self.public_private + " college with a focus on " + self.specialization + ". The cost of attendance is $" + str(self.attendance) + " per year."
        self.energyModifier = 20


class CollegeMajorClass:
    """
    College Major definition class

    Attributes:
        id: Unique identifier
        title: Major name
        related_jobs: List of job titles related to this major
        colleges: List of college IDs offering this major
    """
    def __init__(self, title, related_jobs, colleges):
        self.id = uuid.uuid4().hex
        self.title = title
        self.related_jobs = related_jobs
        # Store the UUIDs of the colleges
        self.colleges = [college.id for college in colleges]


class FocusClass:
    """
    Focus type for activities (work/study approach)

    Attributes:
        id: Focus ID number
        focus_name: Name of the focus type
        description: Description of the focus
        energyModifier: Energy cost modifier (positive = more energy used)

    Focus Types:
        - Work Hard: +10 energy, improves performance/GPA
        - Slack Off: -10 energy, reduces performance/GPA
        - Socialize: +10 energy, builds relationships
        - Balanced: 0 energy, neutral approach
    """
    def __init__(self, id, focus_name, description, energyModifier):
        self.id = id
        self.focus_name = focus_name
        self.description = description
        self.energyModifier = energyModifier  # Energy cost modifier


class ExtraCurricular:
    """
    Extracurricular activity definition

    Attributes:
        id: Unique identifier
        title: Activity name
        type: Activity type ('extracurricular')
        focus: Default focus type for this activity
        description: Description of the activity
        energyModifier: Energy cost
        image: Optional image URL
    """
    def __init__(self, title, focus, description, energyModifier, image=None):
        self.id = uuid.uuid4().hex
        self.title = title
        self.image = image
        self.type = 'extracurricular'
        self.focus = focus
        self.description = description
        self.energyModifier = energyModifier


# ============================================================
# School Generation Functions
# ============================================================

def getSchools():
    """
    Generate lists of elementary and high schools

    Returns:
        tuple: (elementary_schools, high_schools) lists

    Elementary Schools (6):
        - Maple Elementary School (Public, 350 students)
        - Eagle Private Academy (Private, 200 students)
        - Greenwood Elementary (Public, 400 students)
        - Bright Stars School (Private, 150 students)
        - Lakeview Elementary (Public, 320 students)
        - Grand Oak Elementary (Public, 500 students)

    High Schools (6):
        - Valley High School (Public, 1200 students, 3.2 GPA avg)
        - Prestige Prep School (Private, 600 students, 3.8 GPA avg)
        - Northview High (Public, 1500 students, 2.8 GPA avg)
        - Academic Excellence Institute (Private, 450 students, 4.0 GPA avg)
        - Harmony High (Public, 1400 students, 3.0 GPA avg)
        - Mountain Ridge High (Public, 1300 students, 3.4 GPA avg)
    """
    elementary_schools = []
    high_schools = []

    # Creating 6 elementary schools
    elementary_schools.append(ElementarySchoolClass('Elementary', 'Maple Elementary School', 'Public', 350, 20, 'https://cdn.discordapp.com/attachments/1106614533402931284/1122300601498341406/craig_vg_elementary_school_exterior_cartoon_styled_da8ab4a0-c409-448f-b8b2-049d121cb0ea.png?ex=660899e2&is=65f624e2&hm=1907c0dc131481013f94e7cce46f37ab82c0c762e3949a8e79bef8c38c32c38c&'))
    elementary_schools.append(ElementarySchoolClass('Elementary', 'Eagle Private Academy', 'Private', 200, 15, 'https://cdn.discordapp.com/attachments/1106614533402931284/1122928884829147146/craig_vg_Eagle_Private_Academy_elementary_school_exterior_cute__931b347c-5df2-4fb4-87f7-bfa5b58f8b84.png?ex=6601a885&is=65ef3385&hm=6a5dce5d607412b4878e612ed2a5eefdd1c2746e6883ab3124831de88b636939&'))
    elementary_schools.append(ElementarySchoolClass('Elementary', 'Greenwood Elementary', 'Public', 400, 22, 'https://cdn.discordapp.com/attachments/1106614533402931284/1122929005637664859/craig_vg_greenwood_elementary_school_exterior_cute_cartoon_styl_ae8f5fed-010a-430b-834b-53ddd0db40fa.png?ex=6601a8a1&is=65ef33a1&hm=bbd890e95290cc61e41d4fb6512cbd8fcadf54a0240262d8562dc73392cf83f2&'))
    elementary_schools.append(ElementarySchoolClass('Elementary', 'Bright Stars School', 'Private', 150, 12, 'https://cdn.discordapp.com/attachments/1106614533402931284/1122929045429035099/craig_vg_bright_stars_private_elementary_school_exterior_exteri_dc55defa-dee0-416a-91e4-00391c81b837.png?ex=6601a8ab&is=65ef33ab&hm=0d383d6ee4000c78d4b4cb673aedb6177b0aed7eb1fd1e1ed845a4f9fbf98d8d&'))
    elementary_schools.append(ElementarySchoolClass('Elementary', 'Lakeview Elementary', 'Public', 320, 18, 'https://cdn.discordapp.com/attachments/1106614533402931284/1122929459725611018/craig_vg_lakeview_public_elementary_school_exterior_exterior_cu_77fa2429-68af-4ce3-9fff-cee403a903d5.png?ex=6601a90e&is=65ef340e&hm=d892ce5ac1fd33e6325c7f888c7500936c57ddd7b6f00bf3ee51c0dfe1ec9547&'))
    elementary_schools.append(ElementarySchoolClass('Elementary', 'Grand Oak Elementary', 'Public', 500, 25, 'https://cdn.discordapp.com/attachments/1106614533402931284/1122929345569243217/craig_vg_grand_oak_public_elementary_school_exterior_cute_carto_9786a196-ed1c-4026-a81c-e439325eb066.png?ex=6601a8f3&is=65ef33f3&hm=32c003a87a6329076bd52a53d93602a27a8b363955f83702bcba6511eb924d9b&'))

    # Creating 6 high schools
    high_schools.append(HighSchoolClass('High', 'Valley High School', 'Public', 1200, 25, 3.2, 'https://cdn.midjourney.com/d5a4aae1-b6a3-4718-affb-b6189e946c7c/0_3.png'))
    high_schools.append(HighSchoolClass('High', 'Prestige Prep School', 'Private', 600, 10, 3.8, 'https://cdn.midjourney.com/5bb6f536-ce7e-4d30-9d7b-4082c3a712ce/0_2.png'))
    high_schools.append(HighSchoolClass('High', 'Northview High', 'Public', 1500, 28, 2.8, 'https://cdn.midjourney.com/5bb6f536-ce7e-4d30-9d7b-4082c3a712ce/0_0.png'))
    high_schools.append(HighSchoolClass('High', 'Academic Excellence Institute', 'Private', 450, 8, 4.0, 'https://cdn.midjourney.com/db6acff2-7621-4ba9-a777-d1a64eea42e9/0_1.png'))
    high_schools.append(HighSchoolClass('High', 'Harmony High', 'Public', 1400, 27, 3.0, 'https://cdn.midjourney.com/c3bb7a11-2112-477b-b1e9-24506a30e54a/0_2.png'))
    high_schools.append(HighSchoolClass('High', 'Mountain Ridge High', 'Public', 1300, 24, 3.4, 'https://cdn.midjourney.com/0d5f79ee-6707-44e2-8b45-19463aa80027/0_1.png'))

    return elementary_schools, high_schools


def getColleges():
    """
    Generate list of colleges and universities

    Returns:
        list: List of CollegeClass objects

    Colleges (10):
        - University of Science (Public, $10k/yr)
        - Artistic Minds University (Private, $20k/yr)
        - Eastern Commerce College (Public, $8k/yr)
        - Law and Governance University (Private, $25k/yr)
        - Institute of Tech Innovation (Public, $15k/yr)
        - Liberal Arts Academy (Private, $18k/yr)
        - Northern Agriculture College (Public, $12k/yr)
        - Health and Medicine University (Private, $30k/yr)
        - Oceanography Institute (Public, $9k/yr)
        - Performing Arts School (Private, $22k/yr)
    """
    colleges = []

    # Creating 10 colleges with cost
    colleges.append(CollegeClass('College', 'University of Science', 'Public', 15000, 3.5, 28, 'Science and Engineering', 10000, 'https://cdn.discordapp.com/attachments/1106614533402931284/1122925527645302884/craig_vg_university_of_science_exterior_cute_cartoon_style_ae7b28ef-5429-4bb9-a0f2-cc01a3e18816.png?ex=6601a564&is=65ef3064&hm=dc2b51c1554d88a485a7fcafb6c0321a15db6df711f26ee773b0f2db5fb8879f&'))
    colleges.append(CollegeClass('College', 'Artistic Minds University', 'Private', 6000, 3.2, 24, 'Arts and Humanities', 20000, 'https://cdn.discordapp.com/attachments/1106614533402931284/1122926848603594784/craig_vg_liberal_arts_academy_exterior_cute_cartoon_style_e8491157-137f-403e-9297-c9c5da4a8a0a.png?ex=6601a69f&is=65ef319f&hm=b0a07c2966ef02aa2aa58c558af496aaae91109e72b6a4cdc5f5f6e59ac7424e&'))
    colleges.append(CollegeClass('College', 'Eastern Commerce College', 'Public', 20000, 3.1, 23, 'Business and Economics', 8000, 'https://cdn.discordapp.com/attachments/1106614533402931284/1122926188382404790/craig_vg_eastern_commerce_business_college_exterior_cute_cartoo_c6bde33f-b08a-4eea-a895-d80370de3229.png?ex=6601a602&is=65ef3102&hm=e67a4a0b34c6b981745cb4b3a714aae18df5087d92fc4deacfaf9c22dd8565ea&'))
    colleges.append(CollegeClass('College', 'Law and Governance University', 'Private', 7000, 3.6, 30, 'Law and Politics', 25000, 'https://cdn.discordapp.com/attachments/1106614533402931284/1122926228945502301/craig_vg_law_and_governance_politics_university_exterior_cute_c_278d3de4-6136-44fe-ad9c-6783c5116add.png?ex=6601a60b&is=65ef310b&hm=db38963bdc4f04fc7cb65baf3a9825e65c445792cc52efd4f061c3a0324025d3&'))
    colleges.append(CollegeClass('College', 'Institute of Tech Innovation', 'Public', 12000, 3.7, 29, 'Technology and Computer Science', 15000, 'https://cdn.discordapp.com/attachments/1106614533402931284/1122926414014988339/craig_vg_institute_of_tech_innovation_exterior_cute_cartoon_sty_6d8ed45a-8271-401c-8e4d-2e722996ab61.png?ex=6601a638&is=65ef3138&hm=7c6bacff997c8364c4a7f233175d37ed179c258a4be7b51c38fef4441dfe5cc8&'))
    colleges.append(CollegeClass('College', 'Liberal Arts Academy', 'Private', 4000, 3.3, 25, 'Liberal Arts', 18000, 'https://cdn.discordapp.com/attachments/1106614533402931284/1122926848603594784/craig_vg_liberal_arts_academy_exterior_cute_cartoon_style_e8491157-137f-403e-9297-c9c5da4a8a0a.png?ex=6601a69f&is=65ef319f&hm=b0a07c2966ef02aa2aa58c558af496aaae91109e72b6a4cdc5f5f6e59ac7424e&'))
    colleges.append(CollegeClass('College', 'Northern Agriculture College', 'Public', 14000, 3.0, 22, 'Agriculture and Environmental Science', 12000, 'https://cdn.discordapp.com/attachments/1106614533402931284/1122926919202127983/craig_vg_northern_Agriculture_College_exterior_cute_cartoon_sty_0f1f6107-15ae-4887-b6e5-adad78f14331.png?ex=6601a6b0&is=65ef31b0&hm=aeb13f6b17833ff6fcdb8252c92aa9e4b07aafc68bab2ff9810c31fe70636041&'))
    colleges.append(CollegeClass('College', 'Health and Medicine University', 'Private', 8000, 3.7, 31, 'Health and Medicine', 30000, 'https://cdn.discordapp.com/attachments/1106614533402931284/1122927019810893845/craig_vg_health_and_medicine_university_exterior_cute_cartoon_s_5e0f5e0d-a1c5-40ae-a165-bcca1ce31d8d.png?ex=6601a6c8&is=65ef31c8&hm=3640c11e1da42ef3fc0a2a370dbd7606bac4bcf83f71fdeabc3a1ea9b3f3786d&'))
    colleges.append(CollegeClass('College', 'Oceanography Institute', 'Public', 10000, 3.4, 26, 'Marine Science', 9000, 'https://cdn.discordapp.com/attachments/1106614533402931284/1122927410908778637/craig_vg_oceanography_institute_exterior_cute_cartoon_style_f0cf82f8-d2ec-45c6-b527-c9d26fe6621e.png?ex=6601a725&is=65ef3225&hm=1f6e4d7ce9606c481ae78762f3bf007565f21e51936791f05b08e37d2e2fd478&'))
    colleges.append(CollegeClass('College', 'Performing Arts School', 'Private', 5000, 3.2, 24, 'Performing Arts', 22000, 'https://cdn.discordapp.com/attachments/1106614533402931284/1122928193641398302/craig_vg_performing_arts_school_exterior_cute_cartoon_style_e1cde50c-785d-4f37-b26b-19ea896756ff.png?ex=6601a7e0&is=65ef32e0&hm=6085c425d06230acf6a36812124cf1db52325c050eab56fd7f77a8cc0062a1b5&'))

    return colleges


def getMajors(colleges):
    """
    Generate list of college majors with associated colleges and careers

    Args:
        colleges (list): List of CollegeClass objects

    Returns:
        list: List of CollegeMajorClass objects

    Majors (15):
        - Computer Science → Software Engineer
        - Nursing → Registered Nurse
        - Education → Teachers, Counselor
        - Criminal Justice → Police Officer
        - Accounting → Accountant
        - Culinary Arts → Chef
        - Law → Lawyer
        - Automotive Technology → Automotive Mechanic
        - Business → Sales Rep, Real Estate Agent
        - Architecture → Architect
        - Medicine → Physician, Dentist, Pharmacist
        - Library Science → Librarian
        - Journalism → Journalist
        - Psychology → Counselor
        - Veterinary Medicine → Veterinarian
    """
    majors = []

    # Associate majors with colleges using the colleges' UUIDs
    majors.append(CollegeMajorClass('Computer Science', ['Software Engineer'], [colleges[0], colleges[4]]))
    majors.append(CollegeMajorClass('Nursing', ['Registered Nurse'], [colleges[7]]))
    majors.append(CollegeMajorClass('Education', ['High School Teacher', 'Elementary School Teacher', 'Counselor'], [colleges[5]]))
    majors.append(CollegeMajorClass('Criminal Justice', ['Police Officer'], [colleges[3]]))
    majors.append(CollegeMajorClass('Accounting', ['Accountant'], [colleges[2]]))
    majors.append(CollegeMajorClass('Culinary Arts', ['Chef'], [colleges[1], colleges[9]]))
    majors.append(CollegeMajorClass('Law', ['Lawyer'], [colleges[3]]))
    majors.append(CollegeMajorClass('Automotive Technology', ['Automotive Mechanic'], [colleges[0]]))
    majors.append(CollegeMajorClass('Business', ['Sales Representative', 'Real Estate Agent'], [colleges[2]]))
    majors.append(CollegeMajorClass('Architecture', ['Architect'], [colleges[0], colleges[4]]))
    majors.append(CollegeMajorClass('Medicine', ['Physician', 'Dentist', 'Pharmacist'], [colleges[7]]))
    majors.append(CollegeMajorClass('Library Science', ['Librarian'], [colleges[5]]))
    majors.append(CollegeMajorClass('Journalism', ['Journalist'], [colleges[1]]))
    majors.append(CollegeMajorClass('Psychology', ['Counselor'], [colleges[5], colleges[7]]))
    majors.append(CollegeMajorClass('Veterinary Medicine', ['Veterinarian'], [colleges[6]]))

    return majors


# ============================================================
# Focus Management Functions
# ============================================================

def getFocuses():
    """
    Get list of available focus types for activities

    Returns:
        list: List of FocusClass objects

    Focus Types:
        1. Work Hard: +10 energy cost, improves performance/GPA
        2. Slack Off: -10 energy cost, reduces performance/GPA
        3. Socialize: +10 energy cost, builds relationships
        4. Balanced: 0 energy cost, neutral approach
    """
    focuses = []
    focuses.append(FocusClass(1, 'Work Hard', 'Work hard to get ahead', 10))
    focuses.append(FocusClass(2, 'Slack Off', 'Slack off at work to avoid stress', -10))
    focuses.append(FocusClass(3, 'Socialize', 'Socialize with others to build relationships', 10))
    focuses.append(FocusClass(4, 'Balanced', 'Balance work and socializing', 0))
    return focuses


def randomFocus():
    """
    Get a random focus type

    Returns:
        FocusClass: Random focus object
    """
    return random.choice(getFocuses())


def getFocus(focusName):
    """
    Get focus object by name

    Args:
        focusName (str): Name of the focus type

    Returns:
        FocusClass: Matching focus object or None
    """
    for focus in getFocuses():
        if focus.focus_name == focusName:
            return focus
    return None


def update_focus(player, activity_id, new_focus):
    """
    Update the focus for a specific activity

    Args:
        player: Player object containing character
        activity_id (str): ID of the activity to update
        new_focus (str): Name of the new focus type

    Updates:
        - Changes the focus in the activity record
        - Recalculates peak energy for the character
    """
    # Import here to avoid circular dependency
    from stats.stats_manager import getPeakEnergy

    for activityRecord in player.c.activityRecords:
        if str(activityRecord.id).strip() == str(activity_id).strip():
            print(activityRecord.focus + " -> " + new_focus)
            new_focus = getFocus(new_focus)
            print("peak energy change " + str(player.c.peakEnergy) + " + " + str(new_focus.energyModifier) + " -> " + str(player.c.peakEnergy + new_focus.energyModifier))
            activityRecord.focus = new_focus.focus_name
            getPeakEnergy(player.c)
            break
    else:
        print("No matching activity found.")


# ============================================================
# Extracurricular Management Functions
# ============================================================

def getExtraCurriculars():
    """
    Get list of available extracurricular activities

    Returns:
        list: List of ExtraCurricular objects

    Activities (9):
        - Choir (Work Hard, 20 energy)
        - Musical Theater (Socialize, 30 energy)
        - Debate Team (Work Hard, 20 energy)
        - Writing Club (Balanced, 10 energy)
        - Robotics Team (Work Hard, 40 energy)
        - Baseball (Socialize, 20 energy)
        - Basketball (Socialize, 30 energy)
        - Soccer (Socialize, 30 energy)
        - Football (Socialize, 40 energy)
    """
    extraCurriculars = []
    extraCurriculars.append(ExtraCurricular('Choir', 'Work Hard', 'Perfect your singing skills and perform in concerts', 20, 'https://media.discordapp.net/attachments/1106614533402931284/1122691487180795965/craig_vg_school_choir_class_cute_cartoon_style_ba317c8f-6ed0-4955-84cd-faeeff28ee68.png?ex=6600cb6d&is=65ee566d&hm=4dae9a84443a033d8e62046463f6605ef7d250e83a6333436117c152b9169ece&=&format=png&quality=lossless&width=526&height=526'))
    extraCurriculars.append(ExtraCurricular('Musical Theater', 'Socialize', 'Perform in musicals and bond with the cast', 30, 'https://media.discordapp.net/attachments/1106614533402931284/1122692114644484197/craig_vg_Musical_theater_class_cute_cartoon_style_615a8d72-6c01-445e-b2da-ff0f19ede550.png?ex=6600cc02&is=65ee5702&hm=57b2eddb164479b16e47540ffdadf5f0169d390588d8574db07ef7e0d19fa856&=&format=png&quality=lossless&width=526&height=526'))
    extraCurriculars.append(ExtraCurricular('Debate Team', 'Work Hard', 'Develop your debating skills and compete against other teams', 20, 'https://cdn.discordapp.com/attachments/1106614533402931284/1218745363201134603/craig_vg_debate_team_class_cute_cartoon_style_595c6e7a-b077-47e7-b62c-669464404a69.png?ex=6608c811&is=65f65311&hm=85b9709dcb26d575d301a7f16eaae9cc2795a51ad44f6adc7418b292f77c89ea&'))
    extraCurriculars.append(ExtraCurricular('Writing Club', 'Balanced', 'Improve your writing and share ideas with other members', 10, 'https://media.discordapp.net/attachments/1106614533402931284/1122923754650079362/craig_vg_writing_club_class_school_cute_cartoon_style_aa1e50e1-3d12-45f1-84df-5e2a743b72b9.png?ex=6601a3be&is=65ef2ebe&hm=cfc45cd684013596ab1d56ea8c0d58ddd12572de3062810a617b02ac400935ab&=&format=png&quality=lossless&width=526&height=526'))
    extraCurriculars.append(ExtraCurricular('Robotics Team', 'Work Hard', 'Design and build robots for competitions', 40, 'https://cdn.discordapp.com/attachments/1106614533402931284/1122923789412483123/craig_vg_robotics_team_school_cute_cartoon_style_892517c3-f69a-4748-8d13-44a91809e392.png?ex=6601a3c6&is=65ef2ec6&hm=17c0fe3680c5df5ba682952ba310ce16ce62e7ae3d98b667abe2074e0611822a&'))
    extraCurriculars.append(ExtraCurricular('Baseball', 'Socialize', 'Play baseball and spend time with teammates', 20, 'https://cdn.discordapp.com/attachments/1106614533402931284/1122692176917315595/craig_vg_baseball_team_cute_cartoon_style_941e60c1-1d96-43ef-b6eb-d1e9e3339836.png?ex=6600cc11&is=65ee5711&hm=fdf5b18fb53b4281af65611724565bfd149f63b18d4fa719b91b171ff5d9844c&'))
    extraCurriculars.append(ExtraCurricular('Basketball', 'Socialize', 'Play basketball and bond with teammates', 30, 'https://cdn.discordapp.com/attachments/1106614533402931284/1122924183979040798/craig_vg_basketball_team_kids_cute_cartoon_style_4ce4fddf-4520-40ea-97cc-ddecbac6f7e9.png?ex=6601a424&is=65ef2f24&hm=7bc865567e44ca301b6250a29ddba093b16cdff19c4d6924ecfc5c0e3deee2dd&'))
    extraCurriculars.append(ExtraCurricular('Soccer', 'Socialize', 'Play soccer and spend time with teammates', 30, 'https://cdn.discordapp.com/attachments/1106614533402931284/1122692364624986174/craig_vg_soccer_team_class_cute_cartoon_style_b6f60c0f-36a3-4326-b108-fa7935991cf7.png?ex=6600cc3e&is=65ee573e&hm=a50d45a8bf073dbd1bd0c6005a2781414f87d16d7aa1f60ff2fa0c3eae9139b8&'))
    extraCurriculars.append(ExtraCurricular('Football', 'Socialize', 'Play football and bond with teammates', 40, 'https://cdn.discordapp.com/attachments/1106614533402931284/1122924237175394344/craig_vg_american_football_team_cute_cartoon_style_9dc1adfc-bed7-445c-a7d8-333620f0e91f.png?ex=6601a431&is=65ef2f31&hm=4ebd26a3ba5b24a716dab9e108db8ff9fb037b9a38b74e3faca8f1fc754df8e5&'))

    return extraCurriculars


def randomExtraCurricular(player):
    """
    Get a random extracurricular activity from player's list

    Args:
        player: Player object containing extraCurriculars list

    Returns:
        ExtraCurricular: Random extracurricular object
    """
    return random.choice(player.extraCurriculars)


def setExtracurricular(person, extraCurricularClass, date):
    """
    Assign an extracurricular activity to a person

    Args:
        person: Person object to assign activity to
        extraCurricularClass: ExtraCurricular object to assign
        date: Date the activity was started

    Updates:
        - Adds activity to person.activities
        - Creates and adds ActivityRecord
    """
    # Import here to avoid circular dependency
    from core.models import ActivityRecord

    print("setting extracurricular" + extraCurricularClass.title + date)
    person.activities.append(extraCurricularClass)
    person.activityRecords.append(ActivityRecord(extraCurricularClass.id, extraCurricularClass.type, date))


def applyForExtracurricular(player, extracurricularID):
    """
    Apply for an extracurricular activity

    Args:
        player: Player object
        extracurricularID (str): ID of the extracurricular to apply for

    Updates:
        - Assigns extracurricular to player character
        - Creates classmates for the activity
        - Adds message to message queue
    """
    # Import here to avoid circular dependency
    from character.character_manager import create_classmates

    for extracurricular in player.extraCurriculars:
        if (extracurricular.id == extracurricularID):
            setExtracurricular(player.c, extracurricular, player.date)
            player.messageQueue.append("You have applied for " + extracurricular.title + ".")
            player = create_classmates(player, extracurricular)


def quitExtraCurricular(player, extraCurricularID):
    """
    Quit an extracurricular activity

    Args:
        player: Player object
        extraCurricularID (str): ID of the extracurricular to quit

    Updates:
        - Removes activity from player.c.activities
        - Removes activity record from player.c.activityRecords
        - Adds message to message queue
    """
    for extracurricular in player.extraCurriculars:
        if (extracurricular.id == extraCurricularID):
            for activity in player.c.activities:
                if (activity.id == extracurricular.id):
                    player.c.activities.remove(activity)
            for record in player.c.activityRecords:
                if (record.id == extracurricular.id):
                    player.c.activityRecords.remove(record)
            player.messageQueue.append("You have quit " + extracurricular.title + ".")


# ============================================================
# Education Management Functions
# ============================================================

def handleEducation(person):
    """
    Update GPA based on focus and intelligence

    This function is called during the game loop to update a student's
    academic performance based on their current focus.

    Args:
        person: Person object with current_education attribute

    Updates:
        - Modifies GPA in the person's education activity record
        - GPA increases more with 'Work Hard' focus
        - GPA decreases more with 'Slack Off' focus
        - GPA is clamped between 0 and 100
    """
    if (getattr(person, 'current_education', False)):
        # Find activity record and update GPA
        for index, item in enumerate(person.activityRecords):
            if item.id == person.current_education.id:
                GPA_modifier = 0
                if (person.current_education.focus == 'Work Hard'):
                    GPA_modifier = 1
                elif (person.current_education.focus == 'Slack Off'):
                    GPA_modifier = -1
                person.activityRecords[index].GPA += random.randint(-1, 1 + GPA_modifier)
                if (person.activityRecords[index].GPA > 100):
                    person.activityRecords[index].GPA = 100
                if (person.activityRecords[index].GPA < 0):
                    person.activityRecords[index].GPA = 0


def setEducation(player, person):
    """
    Set up education for a person based on their age

    This function assigns appropriate education level, school, and creates
    education records for a person. Called during character initialization
    and birthdays.

    Args:
        player: Player object containing schools and colleges lists
        person: Person object to set education for

    Updates:
        - Sets person.education (grade level or degree type)
        - Assigns elementary_school, high_school, or college
        - Adds school to person.activities
        - Creates EducationRecord in person.activityRecords
        - Sets person.current_education
        - Sets person.occupation ('student', 'school', or 'work')

    Education Levels by Age:
        5: kindergarten
        6-11: 1st-6th grade (elementary_school)
        12-14: 7th-9th grade (elementary_school)
        15-17: 10th-12th grade (high_school)
        18+: college (60% chance)
            18: college yr 1
            19+: associate_degree (65% chance)
            20: college yr 3 (35% chance of continuing)
            21+: bachelors_degree
            (20% chance): doctorate_degree

    Returns:
        person: Updated person object
    """
    # Import here to avoid circular dependency
    from core.models import EducationRecord

    school = None

    # Set education level based on age
    if (person.ageYears == 5):
        person.education = "kindergarten"
    if (person.ageYears == 6):
        person.education = "1st"
    if (person.ageYears == 7):
        person.education = "2nd"
    if (person.ageYears == 8):
        person.education = "3rd"
    if (person.ageYears == 9):
        person.education = "4th"
    if (person.ageYears == 10):
        person.education = "5th"
    if (person.ageYears == 11):
        person.education = "6th"
    if (person.ageYears == 12):
        person.education = "7th"
    if (person.ageYears == 13):
        person.education = "8th"
    if (person.ageYears == 14):
        person.education = "9th"
    if (person.ageYears == 15):
        person.education = "10th"
    if (person.ageYears == 16):
        person.education = "11th"
    if (person.ageYears == 17):
        person.education = "high_school"

    # Assign school based on age
    if (person.ageYears < 14):
        person.elementary_school = random.choice(player.elementary_schools)
        person.activities.append(person.elementary_school)
    elif (person.ageYears < 18):
        person.high_school = random.choice(player.high_schools)
        person.activities.append(person.high_school)

    # Determine if person goes to college (60% chance)
    collegeRatio = random.random()
    if person.ageYears >= 18 and collegeRatio >= .6:
        person.occupation = 'school'
        if (person.ageYears == 18):
            person.education = "college yr 1"
        if (person.ageYears >= 19):
            person.education = "associate_degree"
        if (collegeRatio >= .35):
            if (person.ageYears == 20):
                person.education = "college yr 3"
            if (person.ageYears >= 21):
                person.education = "bachelors_degree"
            if (collegeRatio > .2):
                person.education = "doctorate_degree"
        person.college = random.choice(player.colleges)
        person.activities.append(person.college)
    else:
        person.occupation = 'work'

    # Create education records
    if (person.elementary_school):
        person.current_education = EducationRecord(educationLevel=person.education, location=person.elementary_school, date=player.date)
        person.activityRecords.append(person.current_education)
    if (person.high_school):
        person.current_education = EducationRecord(educationLevel=person.education, location=person.high_school, date=player.date)
        person.activityRecords.append(person.current_education)
    if (person.college):
        person.current_education = EducationRecord(educationLevel=person.education, location=person.college, date=player.date)
        person.activityRecords.append(person.current_education)

    # Set occupation for children
    if person.ageYears < 18 and person.ageYears > 4:
        person.occupation = 'student'

    return person
