#!/usr/bin/env python
"""
Job Management Module

This module contains all job and occupation-related classes and functions for the BaoLife game.
It handles job creation, assignment, performance tracking, promotions, and terminations.

Classes:
    - JobLevel: Represents a level/position within an occupation
    - OccupationClass: Represents a specific occupation with multiple levels

Functions:
    - getOccupations(): Returns all available occupations in the game
    - randomJob(player, person): Assigns a random job to a person
    - setJob(person, jobClass, date): Sets a specific job for a person
    - handleJob(player, person): Updates job performance and handles promotions/terminations
    - applyForJob(player, jobID): Allows player to apply for a specific job
    - quitJob(player, jobID): Allows player to quit their current job
"""

import random
import uuid


class JobLevel:
    """
    Represents a specific level/position within an occupation.

    Attributes:
        id (str): Unique identifier for the job level
        level (str): Name of the position (e.g., "Junior Software Engineer")
        salary (int): Monthly salary for this position
        energy_modifier (int): Energy cost modifier for this position
    """
    def __init__(self, level, salary, energy_modifier):
        self.id = uuid.uuid4().hex
        self.level = level
        self.salary = salary
        self.energy_modifier = energy_modifier


class OccupationClass:
    """
    Represents an occupation/job with multiple career levels.

    This class inherits from locationClass as occupations are also locations
    where characters spend their time.

    Attributes:
        title (str): Name of the occupation
        description (str): Description of the occupation
        shifts (str): Type of work shifts (e.g., "Day shift", "Rotating shifts")
        hourType (str): Full-time or part-time (default: "full-time")
        requirements (str): Education requirement (e.g., "bachelors_degree", "high_school", "none")
        type (str): Set to "job"
        levels (list): List of JobLevel instances representing career progression
        image (str): URL to occupation image
    """
    def __init__(self, title, description, shifts, requirements, levels, image=None):
        from core.models import locationClass

        self.id = uuid.uuid4().hex
        self.type = 'occupation'
        self.image = image
        self.title = title
        self.description = description
        self.shifts = shifts
        self.hourType = 'full-time'
        self.requirements = requirements
        self.type = "job"
        self.levels = levels
        # locationClass properties
        self.people = []


def getOccupations():
    """
    Returns a list of all available occupations in the game.

    Each occupation includes:
        - Job title and description
        - Education requirements
        - Career progression levels with salaries
        - Work shift types
        - Associated imagery

    Returns:
        list: List of OccupationClass instances representing all available jobs
    """
    occupations = [
        OccupationClass(
            "Software Engineer",
            "Develop, test, and maintain software applications",
            "Day shift",
            "bachelors_degree",
            [
                JobLevel('Junior Software Engineer', 2000, 30),
                JobLevel('Software Engineer', 3000, 40),
                JobLevel('Senior Software Engineer', 4000, 50),
                JobLevel('Software Engineering Manager', 6000, 60),
                JobLevel('CTO', 10000, 70)
            ],
            image="https://cdn.discordapp.com/attachments/1106614533402931284/1218751308442501290/craig_vg_software_engineer_corporate_office_cartoon_style_82738406-5fab-4a50-a27f-863601e08dd3.png?ex=6608cd9b&is=65f6589b&hm=8565ea7c04f1de8ab02531da9a3c79607e5915b3a3d4f270594a450b21aad93e&"
        ),
        OccupationClass(
            "Registered Nurse",
            "Provide patient care and educate patients about health conditions",
            "Rotating shifts",
            "bachelors_degree",
            [
                JobLevel('Junior Registered Nurse', 1500, 30),
                JobLevel('Registered Nurse', 2000, 40),
                JobLevel('Senior Registered Nurse', 2500, 50),
                JobLevel('Nurse Manager', 3000, 60),
                JobLevel('Director of Nursing', 5000, 70)
            ],
            image="https://cdn.discordapp.com/attachments/1106614533402931284/1218753226258518136/craig_vg_registered_nurse_office_cozy_cartoon_style_androgynous_01b66f1d-c3af-42a9-b475-66d76a6dc286.png?ex=6608cf64&is=65f65a64&hm=4a7fc03f67c83781ac2b7be760b8312c8ef8cd90ac7cf4d8acad8da0ceb360fa&"

        ),
        OccupationClass(
            "Elementary School Teacher",
            "Teach students in a specific subject area",
            "Day shift",
            "bachelors_degree",
            [
                JobLevel('Assistant Teacher', 800, 30),
                JobLevel('Elementary School Teacher', 1100, 40),
                JobLevel('Senior Elementary School Teacher', 1300, 50),
                JobLevel('Head Teacher', 1500, 60),
                JobLevel('Principal', 2000, 70)
            ],
            image="https://cdn.discordapp.com/attachments/1106614533402931284/1218754314999431309/craig_vg_elementary_school_teacher_classroom_cute_cozy_cartoon__b098c603-5958-4ce5-9e08-a8f66dac7d21.png?ex=6608d068&is=65f65b68&hm=48e12924c07a2619796effe2809ce1ab6bc85b596e0c272591c5668565e2de01&"
        ),
        OccupationClass(
            "Police Officer",
            "Maintain public safety and enforce laws",
            "Rotating shifts",
            "high_school",
            [
                JobLevel('Police Officer', 1400, 30),
                JobLevel('Sergeant', 1800, 40),
                JobLevel('Lieutenant', 2200, 50),
                JobLevel('Captain', 2600, 60),
                JobLevel('Chief of Police', 3000, 70)
            ],
            image="https://cdn.discordapp.com/attachments/1106614533402931284/1218755582559911936/craig_vg_police_officer_at_work_cozy_cartoon_style_9c15e689-4dfd-4aa5-9239-f751124cb27a.png?ex=6608d196&is=65f65c96&hm=721d09d328b54239e7376ad531546153d017b0d73435d5d508caa3765c53e149&"
        ),
        OccupationClass(
            "Accountant",
            "Prepare and examine financial records",
            "Day shift",
            "bachelors_degree",
            [
                JobLevel('Junior Accountant', 1200, 30),
                JobLevel('Accountant', 1600, 40),
                JobLevel('Senior Accountant', 2000, 50),
                JobLevel('Accounting Manager', 2400, 60),
                JobLevel('Chief Financial Officer', 3000, 70)
            ],
            image="https://cdn.discordapp.com/attachments/1106614533402931284/1218756621971488858/craig_vg_corporate_accountant_office_cozy_cartoon_style_4a49f16b-6796-4d52-aad8-5011adb7090d.png?ex=6608d28e&is=65f65d8e&hm=d507d0ece82ff2310889659ad7d1da427691c2519198ab9142936d7663a928de&"
        ),
        OccupationClass(
            "Chef",
            "Prepare and cook meals in a restaurant",
            "Variable shifts",
            "high_school",
            [
                JobLevel('Line Cook', 800, 30),
                JobLevel('Sous Chef', 1100, 40),
                JobLevel('Head Chef', 1400, 50),
                JobLevel('Executive Chef', 1700, 60),
                JobLevel('Master Chef', 2000, 70)#YES CHEF
            ],
            image="https://cdn.discordapp.com/attachments/1106614533402931284/1218756781694652496/craig_vg_chef_kitchen_cartoon_style_972262c1-9427-423c-9dc0-7048bfcabaac.png?ex=6608d2b4&is=65f65db4&hm=e2d358babeccde4c88184cbe7d42dabc03f5b1fa0e0ef7e2353225edd0e52e57&"
        ),
        OccupationClass(
            "Lawyer",
            "Represent clients in legal proceedings",
            "Variable shifts",
            "doctorate_degree",
            [
                JobLevel('Associate', 2000, 30),
                JobLevel('Senior Associate', 2500, 40),
                JobLevel('Partner', 3000, 50),
                JobLevel('Senior Partner', 3500, 60),
                JobLevel('Managing Partner', 4000, 70)
            ],
            image="https://cdn.discordapp.com/attachments/1106614533402931284/1218758065491284038/craig_vg_lawyer_office_cute_cozy_cartoon_style_075eff79-b3b4-49ff-93a7-a555999f205e.png?ex=6608d3e6&is=65f65ee6&hm=2788d48cf6991bcd5986d945f8baa6766b39bae4619bebddb2bc7ecb21fd028b&"
        ),
        OccupationClass(
            "Automotive Mechanic",
            "Repair and maintain vehicles",
            "Day shift",
            "high_school",
            [
                JobLevel('Apprentice Mechanic', 800, 30),
                JobLevel('Automotive Mechanic', 1000, 40),
                JobLevel('Master Mechanic', 1200, 50),
                JobLevel('Shop Foreman', 1400, 60),
                JobLevel('Service Manager', 1600, 70)
            ],
            "https://cdn.discordapp.com/attachments/1106614533402931284/1218758042624196718/craig_vg_automotove_mechanic_shop_cute_cozy_cartoon_style_0b0eb986-dcc5-4d8e-9d41-76b56f0e84bc.png?ex=6608d3e0&is=65f65ee0&hm=56e4cf50ab694e4f80425bfb46581a355db6f15bf7a217ec6477a91dc387e871&"
        ),
        OccupationClass(
            "Sales Representative",
            "Sell goods or services to businesses or consumers",
            "Variable shifts",
            "high_school",
            [
                JobLevel('Junior Sales Representative', 1000, 30),
                JobLevel('Sales Representative', 1300, 40),
                JobLevel('Senior Sales Representative', 1600, 50),
                JobLevel('Sales Manager', 1900, 60),
                JobLevel('Director of Sales', 2200, 70)
            ],
            "https://cdn.discordapp.com/attachments/1106614533402931284/1218953374079258644/craig_vg_sales_sleek_corporate_office_cozy_cartoon_style_95ad0a28-f265-43f9-899c-24aee7e3398c.png?ex=660989cb&is=65f714cb&hm=cf971f79b3f32f518fe117cfa88fb5c673a1ca8f964b461226f673a811bab0ed&"
        ),
        OccupationClass(
            "Architect",
            "Design buildings and oversee their construction",
            "Day shift",
            "bachelors_degree",
            [
                JobLevel('Junior Architect', 1400, 30),
                JobLevel('Architect', 1800, 40),
                JobLevel('Senior Architect', 2200, 50),
                JobLevel('Principal Architect', 2600, 60),
                JobLevel('Chief Architect', 3000, 70)
            ],
            "https://cdn.discordapp.com/attachments/1106614533402931284/1218758567411322900/craig_vg_architect_corporate_office_cute_cozy_cartoon_style_ebcb7626-07c9-4a00-8b28-9b4710817ff5.png?ex=6608d45d&is=65f65f5d&hm=47264f737b42a371241ac8f76807dbcb9edb1e1efc998c8b973a3c636db5fcae&"
        ),
        OccupationClass(
            "Physician",
            "Examine patients, diagnose illnesses, and provide treatments",
            "Rotating shifts",
            "doctorate_degree",
            [
                JobLevel('Resident Physician', 2000, 30),
                JobLevel('Physician', 2600, 40),
                JobLevel('Senior Physician', 3200, 50),
                JobLevel('Department Head', 3800, 60),
                JobLevel('Chief Medical Officer', 4400, 70)
            ],
            "https://cdn.discordapp.com/attachments/1106614533402931284/1218953997801750579/craig_vg_doctor_office_cozy_cartoon_style_183f5128-9ddd-46f6-ad7e-5f611e87cfbd.png?ex=66098a60&is=65f71560&hm=9994300ede63da767872bb02cd02f91ee6543d36dc788ea8599352bc8bdad782&"
        ),
        OccupationClass(
            "Dentist",
            "Diagnose and treat issues with patients' teeth",
            "Day shift",
            "doctorate_degree",
            [
                JobLevel('Junior Dentist', 1800, 30),
                JobLevel('Dentist', 2400, 40),
                JobLevel('Senior Dentist', 3000, 50),
                JobLevel('Head of Dentistry', 3600, 60),
                JobLevel('Chief Dental Officer', 4200, 70)
            ],
            "https://cdn.discordapp.com/attachments/1106614533402931284/1218954312642854912/craig_vg_dentist_ofice_cute_cozy_cartoon_style_0930e6ae-e85a-4472-995b-a121aa93e320.png?ex=66098aab&is=65f715ab&hm=3b6814d4b032980dc11dfd7a538ec9913b9ce59cb89f9eee6f954f6f7b86a74b&"
        ),
        OccupationClass(
            "Pharmacist",
            "Provide prescription medications to patients and offer health advice",
            "Variable shifts",
            "doctorate_degree",
            [
                JobLevel('Junior Pharmacist', 1600, 30),
                JobLevel('Pharmacist', 2100, 40),
                JobLevel('Senior Pharmacist', 2600, 50),
                JobLevel('Pharmacy Manager', 3100, 60),
                JobLevel('Director of Pharmacy', 3600, 70)
            ],
            "https://cdn.discordapp.com/attachments/1106614533402931284/1218954456482185276/craig_vg_Pharmacist_office_cute_cozy_cartoon_style_9505ece8-fd4d-456b-ae52-88892ad09071.png?ex=66098acd&is=65f715cd&hm=8c5b0cb7a48ffd823ad963c77614234d973a80dc704552639d517e21bedea1a6&"
        ),
        OccupationClass(
            "Librarian",
            "Help patrons find information and conduct research",
            "Day shift",
            "bachelors_degree",
            [
                JobLevel('Assistant Librarian', 1000, 30),
                JobLevel('Librarian', 1400, 40),
                JobLevel('Senior Librarian', 1800, 50),
                JobLevel('Library Manager', 2200, 60),
                JobLevel('Director of Library Services', 2600, 70)
            ],
            "https://cdn.discordapp.com/attachments/1106614533402931284/1218954416086843483/craig_vg_library_desk_cute_cozy_cartoon_style_f349682a-bd39-4011-9658-2cb982c4e50a.png?ex=66098ac3&is=65f715c3&hm=e62fd84ea784e97201f2149a99394ddfbc6feb12da8e7e1d0c3d510ae0071234&"
        ),
        OccupationClass(
            "Journalist",
            "Report news stories for newspapers, magazines, or television",
            "Variable shifts",
            "bachelors_degree",
            [
                JobLevel('Junior Journalist', 1100, 30),
                JobLevel('Journalist', 1500, 40),
                JobLevel('Senior Journalist', 1900, 50),
                JobLevel('Editor', 2300, 60),
                JobLevel('Editor in Chief', 2700, 70)
            ],
            "https://cdn.discordapp.com/attachments/1106614533402931284/1218954911094407329/craig_vg_journalist_office_cute_cozy_cartoon_style_8b0f9fb3-640b-4b5d-abc8-8561a8e2abe3.png?ex=66098b39&is=65f71639&hm=ceb148f7a309769b7e93be4df2dc9f5468cfdbba57e8f0c5d45a2ff50bf542c5&"
        ),
        OccupationClass(
            "Counselor",
            "Help people manage and overcome mental and emotional issues",
            "Day shift",
            "bachelors_degree",
            [
                JobLevel('Junior Counselor', 1300, 30),
                JobLevel('Counselor', 1700, 40),
                JobLevel('Senior Counselor', 2100, 50),
                JobLevel('Counseling Services Manager', 2500, 60),
                JobLevel('Director of Counseling Services', 2900, 70)
            ],
            "https://cdn.discordapp.com/attachments/1106614533402931284/1218954956317528104/craig_vg_counselor_office_cute_cozy_cartoon_style_4926711f-1ca8-49dd-bc87-0ad5185421c1.png?ex=66098b44&is=65f71644&hm=42dee89643da1ac89dd6cdb6070c805d3383ce6d6f8c96d27ae709894b6b2e4b&"
        ),
        OccupationClass(
            "Veterinarian",
            "Diagnose, treat, and research diseases and injuries in animals",
            "Rotating shifts",
            "doctorate_degree",
            [
                JobLevel('Veterinary Intern', 1800, 30),
                JobLevel('Veterinarian', 2200, 40),
                JobLevel('Senior Veterinarian', 2600, 50),
                JobLevel('Veterinary Services Manager', 3000, 60),
                JobLevel('Director of Veterinary Services', 3400, 70)
            ],
            "https://cdn.discordapp.com/attachments/1106614533402931284/1218955149238866061/craig_vg_Veterinarian_office_cute_cozy_cartoon_style_97327cf0-0a74-42c0-91c3-06ceaf207777.png?ex=66098b72&is=65f71672&hm=5ed90f867b15fd2a375332da1828f36afdd5625c949adb788bb36948ee634d81&"
        ),
        OccupationClass(
            "Electrician",
            "Install, maintain, and repair electrical systems and equipment",
            "Day shift",
            "high_school",
            [
                JobLevel('Apprentice Electrician', 1100, 30),
                JobLevel('Electrician', 1500, 40),
                JobLevel('Master Electrician', 1900, 50),
                JobLevel('Electrical Supervisor', 2300, 60),
                JobLevel('Electrical Contractor', 2700, 70)
            ],
            "https://cdn.discordapp.com/attachments/1106614533402931284/1218955096830902333/craig_vg_Electrician_workspace_cute_cozy_cartoon_style_4e6bfd04-02a2-49bb-a3c1-0c149292e6ca.png?ex=66098b66&is=65f71666&hm=34e72f86570769f336a0606ded7cef2cb2ad87df0d7c344d0457de9cd3e77117&"
        ),
        OccupationClass(
            "Real Estate Agent",
            "Rent, buy, or sell property for clients",
            "Variable shifts",
            "high_school",
            [
                JobLevel('Junior Real Estate Agent', 1200, 30),
                JobLevel('Real Estate Agent', 1600, 40),
                JobLevel('Senior Real Estate Agent', 2000, 50),
                JobLevel('Real Estate Broker', 2400, 60),
                JobLevel('Real Estate Agency Owner', 2800, 70)
            ],
            "https://cdn.discordapp.com/attachments/1106614533402931284/1218955487027134504/craig_vg_real_estate_sales_office_sleek_cute_cozy_cartoon_style_74a66733-7b67-4a53-91df-862b4b132f58.png?ex=66098bc3&is=65f716c3&hm=5f221635151613847ac14cca1b5621506ae48d30cb36248e388467673337252a&"
        ),
        OccupationClass(
            "Graphic Designer",
            "Create visual concepts to communicate ideas",
            "Day shift",
            "bachelors_degree",
            [
                JobLevel('Junior Graphic Designer', 1400, 30),
                JobLevel('Graphic Designer', 1800, 40),
                JobLevel('Senior Graphic Designer', 2200, 50),
                JobLevel('Art Director', 2600, 60),
                JobLevel('Creative Director', 3000, 70)
            ],
            "https://cdn.discordapp.com/attachments/1106614533402931284/1218955697534926898/craig_vg_graphic_designer_workspace_cute_cozy_cartoon_style_9199c766-61be-4c2c-8743-75c43cd7763c.png?ex=66098bf5&is=65f716f5&hm=2cf933b8153b1e6d6e7659c87520ce4ed2434be3066259211b552ffb165ce948&"
        ),
        OccupationClass(
            "Janitor",
            "Perform general cleaning of buildings",
            "Variable shifts",
            "none",
            [
                JobLevel('Janitorial Assistant', 600, 30),
                JobLevel('Janitor', 800, 40),
                JobLevel('Senior Janitor', 1000, 50),
                JobLevel('Janitorial Supervisor', 1200, 60),
                JobLevel('Janitorial Manager', 1400, 70)
            ],
            "https://cdn.discordapp.com/attachments/1106614533402931284/1218956044907184228/craig_vg_janitor_workspace_hallway_cute_cozy_cartoon_style_7833142d-090e-40fe-a18b-cb80c2cac6f0.png?ex=66098c48&is=65f71748&hm=82e0c829876ccabbe1712d4edc601205d91d81e090e8fe53864fcf4e6d76d845&"
        ),
        OccupationClass(
            "Fast Food Worker",
            "Serve food to customers",
            "Variable shifts",
            "none",
            [
                JobLevel('Fast Food Associate', 500, 30),
                JobLevel('Fast Food Worker', 600, 40),
                JobLevel('Fast Food Shift Leader', 700, 50),
                JobLevel('Fast Food Manager', 800, 60),
                JobLevel('Fast Food General Manager', 900, 70)
            ],
            "https://cdn.discordapp.com/attachments/1106614533402931284/1218956084396429493/craig_vg_fast_food_workspace_cute_cozy_cartoon_style_dc2c1155-6230-4aea-9c49-7577b8226e5b.png?ex=66098c51&is=65f71751&hm=b2a2a78a2e9422f7efadf746d677ffba7470411c49fc71c636a0b3a101eaaf16&"
        ),
        OccupationClass(
            "Retail Worker",
            "Assist customers in a retail store",
            "Variable shifts",
            "none",
            [
                JobLevel('Sales Associate', 600, 30),
                JobLevel('Retail Worker', 700, 40),
                JobLevel('Senior Sales Associate', 800, 50),
                JobLevel('Retail Manager', 900, 60),
                JobLevel('Store Owner', 1000, 70)
            ],
            "https://cdn.discordapp.com/attachments/1106614533402931284/1218956885718204657/craig_vg_retail_sales_workspace_cute_cozy_cartoon_style_29a7c377-8dc7-43f4-a095-5003e5c12f21.png?ex=66098d10&is=65f71810&hm=876e10137422615e4bf13cc95ce5d79dab1d56976ed8427040c3be61841d4776&"
        ),
        OccupationClass(
            "Construction Laborer",
            "Perform physical labor at construction sites",
            "Day shift",
            "none",
            [
                JobLevel('Junior Construction Laborer', 800, 30),
                JobLevel('Construction Laborer', 1000, 40),
                JobLevel('Senior Construction Laborer', 1200, 50),
                JobLevel('Construction Foreman', 1400, 60),
                JobLevel('Construction Manager', 1600, 70)
            ],
            "https://cdn.discordapp.com/attachments/1106614533402931284/1218956900909973585/craig_vg_construction_site_cute_cozy_cartoon_style_bf1bdff6-6327-45ae-ab81-25df751d0a52.png?ex=66098d14&is=65f71814&hm=fa32a7967dd3ef8678ec362511fd914f883e7aaa26967b54e6c77d5ff17d31f5&"
        ),
        OccupationClass(
            "Truck Driver",
            "Drive a truck or other large vehicle to transport goods",
            "Variable shifts",
            "none",
            [
                JobLevel('Junior Truck Driver', 900, 30),
                JobLevel('Truck Driver', 1200, 40),
                JobLevel('Senior Truck Driver', 1500, 50),
                JobLevel('Truck Fleet Supervisor', 1800, 60),
                JobLevel('Truck Fleet Manager', 2100, 70)
            ],
            "https://cdn.discordapp.com/attachments/1106614533402931284/1218957188031053844/craig_vg_semi_truck_driver_cabin_cute_cozy_cartoon_style_666a5835-e588-4f40-9b6c-f6fe9527a3fa.png?ex=66098d58&is=65f71858&hm=abdaff2cac295a2b13c9bc5d1ccffc2faddc3f4a31ee02eca04d5113af320566&"
        ),
        OccupationClass(
            "Farm Worker",
            "Plant, cultivate, and harvest agricultural crops",
            "Day shift",
            "none",
            [
                JobLevel('Farm Helper', 700, 30),
                JobLevel('Farm Worker', 900, 40),
                JobLevel('Senior Farm Worker', 1100, 50),
                JobLevel('Farm Supervisor', 1300, 60),
                JobLevel('Farm Manager', 1500, 70)
            ],
            "https://cdn.discordapp.com/attachments/1106614533402931284/1218957775200059442/craig_vg_farm_yard_cute_cozy_cartoon_style_55c20653-9e3d-4885-9e57-ac0d34013cb6.png?ex=66098de4&is=65f718e4&hm=eb60818cac6ffaf993d9feb85867ab9695f4c0e61f98e414a38f8cf712ddce1e&"
        ),
        OccupationClass(
            "Landscaper",
            "Maintain the appearance of outdoor areas and structures",
            "Day shift",
            "none",
            [
                JobLevel('Junior Landscaper', 800, 30),
                JobLevel('Landscaper', 1000, 40),
                JobLevel('Senior Landscaper', 1200, 50),
                JobLevel('Landscaping Supervisor', 1400, 60),
                JobLevel('Landscaping Manager', 1600, 70)
            ],
            "https://cdn.discordapp.com/attachments/1106614533402931284/1218958478345900122/craig_vg_Landscaper_yard_cute_cozy_cartoon_style_98448b52-a2e2-4959-abda-e31a9e6e0227.png?ex=66098e8c&is=65f7198c&hm=15cd527a14f7a2184656a5cd32f910b248f3e2574231adc2406368af06a78df6&"
        ),
        OccupationClass(
            "Home Health Aide",
            "Assist people with disabilities, chronic illness, or cognitive impairment",
            "Rotating shifts",
            "none",
            [
                JobLevel('Junior Home Health Aide', 700, 30),
                JobLevel('Home Health Aide', 900, 40),
                JobLevel('Senior Home Health Aide', 1100, 50),
                JobLevel('Home Health Care Supervisor', 1300, 60),
                JobLevel('Home Health Care Manager', 1500, 70)
            ],
            "https://cdn.discordapp.com/attachments/1106614533402931284/1218957917450141806/craig_vg_Home_Health_Aide_space_cute_cozy_cartoon_style_2b783342-6816-4a6f-a26e-98b1db93c6c3.png?ex=66098e06&is=65f71906&hm=3c43be6946b62a5be34fae42214bdfc15ff7ce13187e436e2bdbb5daeb8342b9&"
        ),
        OccupationClass(
            "Restaurant Server",
            "Take orders and serve food and beverages at restaurants",
            "Variable shifts",
            "none",
            [
                JobLevel('Junior Server', 600, 30),
                JobLevel('Restaurant Server', 800, 40),
                JobLevel('Senior Server', 1000, 50),
                JobLevel('Restaurant Shift Manager', 1200, 60),
                JobLevel('Restaurant Manager', 1400, 70)
            ],
            "https://cdn.discordapp.com/attachments/1106614533402931284/1218958313438576661/craig_vg_Restaurant_Server_space_cute_cozy_cartoon_style_b69b355a-c9f3-498f-a8b5-086d7f1ea43a.png?ex=66098e65&is=65f71965&hm=18265011fe826031f60dbf9b2d9cf93c1f991e637edabd68cfea66a11dcc3434&"
        ),
        OccupationClass(
            "Cashier",
            "Handle customer payments in a retail or other business",
            "Variable shifts",
            "none",
            [
                JobLevel('Junior Cashier', 550, 30),
                JobLevel('Cashier', 700, 40),
                JobLevel('Senior Cashier', 850, 50),
                JobLevel('Shift Supervisor', 1000, 60),
                JobLevel('Store Manager', 1150, 70)
            ],
            "https://cdn.discordapp.com/attachments/1106614533402931284/1218958572419940472/craig_vg_cashier_space_cute_cozy_cartoon_style_decf1bb6-a748-4db2-9c7f-4f73544c9dae.png?ex=66098ea2&is=65f719a2&hm=7be215b18f07093c17201c0b747ec0e4ca9a565b2744c84f7f66e5654196d970&"
        )
    ]
    return occupations


def randomJob(player, person):
    """
    Assigns a random job to a person if they are old enough.

    Args:
        player: The player object containing available occupations
        person: The person object to assign a job to

    Returns:
        person: The person object with job assigned (if age > 22)
    """
    if (person.ageYears > 22):
        job = random.choice(player.occupations)
        setJob(person, job, player.date)
    return person


def setJob(person, jobClass, date):
    """
    Sets a specific job for a person and creates an activity record.

    This function:
    - Assigns the job to the person
    - Adds the job to their activities list
    - Creates an activity record starting at the first level

    Args:
        person: The person object to assign the job to
        jobClass: The OccupationClass instance to assign
        date: The date when the job starts
    """
    from core.models import ActivityRecord

    person.job = jobClass
    person.activities.append(person.job)
    record = ActivityRecord(person.job.id, person.job.type, date)
    record.level = jobClass.levels[0]
    person.activityRecords.append(record)


def handleJob(player, person):
    """
    Updates job performance and handles promotions/terminations.

    This function:
    - Updates performance based on focus level (Work Hard, Balanced, Slack Off)
    - Handles promotions when performance > 90
    - Handles terminations when performance < 10
    - Adds appropriate messages to player's message queue

    Performance modifiers:
    - Work Hard: +2
    - Balanced: 0
    - Slack Off: -1

    Args:
        player: The player object (for message queue and occupations list)
        person: The person whose job performance to update
    """
    from events import messageFunction

    # This sets job performance based on focus and intelligence
    # Use activity record found in person.activityRecords
    for job in player.c.activities:
        if (job.type == 'job'):
            # Find activity record and update performance
            # Loop through person.activityRecords
            for index, item in enumerate(person.activityRecords):
                if item.id == job.id:
                    record = item
                    perf_modifier = 0
                    if (record.focus == 'Work Hard'):
                        perf_modifier += 2
                    elif (record.focus == 'Slack Off'):
                        perf_modifier += -1
                    perf_update = random.randint(-1+perf_modifier, 1+perf_modifier)
                    if (person.id == player.c.id):
                        print("updating performance: " + str(person.activityRecords[index].performance) + " - " + str(perf_update))
                    person.activityRecords[index].performance += perf_update
                    if (record.performance > 100):
                        record.performance = 100
                    if (record.performance < 0):
                        record.performance = 0
                    if (record.performance > 90):
                        for i, level in enumerate(job.levels):
                            if level.level == record.level.level:
                                if i < len(job.levels) - 1:
                                    record.level = job.levels[i+1]
                                    record.performance = 0
                                    message = "You have been promoted to the position of " + job.levels[i+1].level + " at " + job.title + "."
                                    player.messageQueue.append(message)
                                    player.messageQueue.append(messageFunction('promotion', message, player, True, "Promotion", job.image, 0, 0, 0, 0))

                                    break
                    if (record.performance < 10):
                        print('fired')
                        # Fire character
                        person.job = False
                        player.messageQueue.append("You have been fired from your job as " + job.title + ".")
                        break


def applyForJob(player, jobID):
    """
    Allows the player to apply for a specific job.

    This function:
    - Finds the job by ID in available occupations
    - Sets the job for the player's character
    - Creates coworkers for the new job
    - Adds a confirmation message

    Args:
        player: The player object
        jobID: The unique ID of the job to apply for
    """
    for job in player.occupations:
        if (job.id == jobID):
            setJob(player.c, job, player.date)
            player.messageQueue.append("You have applied for the position of " + job.title + ".")
            from character.character_manager import create_coworkers
            player = create_coworkers(player, job)


def quitJob(player, jobID):
    """
    Allows the player to quit their current job.

    This function:
    - Finds the job by ID
    - Removes it from activities list
    - Removes the activity record
    - Sets occupation to 'unemployed'
    - Adds a confirmation message

    Args:
        player: The player object
        jobID: The unique ID of the job to quit
    """
    for job in player.occupations:
        if (job.id == jobID):
            for activity in player.c.activities:
                if (activity.id == job.id):
                    player.c.activities.remove(activity)
            for record in player.c.activityRecords:
                if (record.id == job.id):
                    player.c.activityRecords.remove(record)
            player.c.occupation = 'unemployed'
            player.messageQueue.append("You have quit your job as " + job.title + ".")
