"""
Player factory utilities for testing.

Creates minimal player objects without triggering circular imports.
"""
from types import SimpleNamespace
from datetime import datetime, date
import uuid


def create_minimal_player(age=0, name='Test Player', sex='Male', occupation='preschool', money=0):
    """
    Create a minimal player object for testing without triggering all the imports.

    This factory creates player objects manually to avoid circular import issues
    that occur when using playerClass() constructor.

    Args:
        age: Age in years
        name: First name
        sex: 'Male' or 'Female'
        occupation: Occupation string
        money: Initial money

    Returns:
        A minimal player object with required attributes
    """
    # Create minimal player object
    player = SimpleNamespace()
    player.userID = f'test_user_{uuid.uuid4().hex[:8]}'
    player.controller = 'active'
    player.connection = 'connected'
    player.updateClient = False
    player.status = 'active'
    player.dayEvent = ''
    player.deviceToken = ''
    player.events = set()
    player.askedQuestions = set()
    player.conversations = []
    player.activeDilemmas = []
    player.messageQueue = []
    player.messageLog = []
    player.offlineStats = SimpleNamespace(minutesOffline=0)
    player.gameSpeed = 1
    player.previousGameSpeed = 1
    player.messageEnergyCost = 5

    # Time tracking
    player.ticks = 0
    player.fps = 0
    player.dayOfYear = 1
    player.monthOfYear = 1
    player.season = 'Winter'
    player.date = "01-01"
    player.minuteOfHour = 0
    player.hourOfDay = 0
    player.dayOfWeek = 1
    player.weekDay = 0
    player.weekend = False
    player.weekDayText = "Monday"
    player.daysSinceSchoolStarted = 0
    player.daysUntilSchoolEnds = 0
    player.summerVacation = False
    player.time = "0:00"
    player.message = False

    # Lists
    player.r = []  # relationships
    player.l = []  # locations
    player.relData = []

    # Data arrays (normally loaded from functions)
    player.moods = ["Calm", "Stressed", "Exhausted", "Fulfilled", "Depressed", "Happy"]
    player.elementary_schools = []
    player.high_schools = []
    player.colleges = []
    player.majors = []
    player.focuses = []
    player.storeItems = []
    player.inAppPurchases = []
    player.healthConditions = []
    player.extraCurriculars = []
    player.dateIdeas = []
    player.female_hair_types = ['bob', 'bun', 'curly']
    player.male_hair_types = ['buzzcut', 'short_flat']

    # Create minimal character object
    player.c = SimpleNamespace()
    player.c.id = uuid.uuid4().hex
    player.c.type = "personObject"
    player.c.relationships = []

    # Name
    first, last = name.split(' ') if ' ' in name else (name, 'Player')
    player.c.firstname = first
    player.c.lastname = last

    # Sex/pronouns
    player.c.sex = sex
    if sex == 'Male':
        player.c.pronoun = "He"
    elif sex == 'Female':
        player.c.pronoun = "She"
    else:
        player.c.pronoun = "They"

    # Age
    player.c.ageHours = age * 365 * 24
    player.c.ageDays = age * 365
    player.c.ageYears = age
    player.c.birthday = datetime.now()

    # Stats
    player.c.message = False
    player.c.image = "https://api.dicebear.com/7.x/avataaars/svg"
    player.c.mood = "Calm"
    player.c.money = money
    player.c.weight = 55
    player.c.weightType = 'normal'
    player.c.hunger = 0
    player.c.thirst = 0
    player.c.energy = 100
    player.c.calcEnergy = 100
    player.c.peakEnergy = 100
    player.c.prestige = 0
    player.c.diamonds = 35
    player.c.stress = 0
    player.c.social = 0
    player.c.happiness = 50
    player.c.location = 'home'
    player.c.health = 1
    player.c.deathChance = 0
    player.c.familyLevel = 0
    player.c.spendingHabits = "normal"

    # Activities
    player.c.activityRecords = []
    player.c.education = 'None'
    player.c.current_education = None
    player.c.elementary_school = None
    player.c.high_school = None
    player.c.college = None
    player.c.actScore = 0
    player.c.occupation = occupation
    player.c.job = None
    player.c.major = None
    player.c.minor = None
    player.c.activities = []
    player.c.habits = []
    player.c.healthConditions = []
    player.c.dislikes = []
    player.c.likes = []
    player.c.items = []
    player.c.canDrive = False
    player.c.affinity = 0
    player.c.familiarity = 0
    player.c.status = "alive"
    player.c.dailyPlan = []
    player.c.schedules = []
    player.c.oneTimeEvents = []
    player.c.intraDayMessage = False

    # Avatar settings
    player.c.avatar_settings = SimpleNamespace()
    player.c.avatar_settings.hair = 'ShortHairShortFlat' if sex == 'Male' else 'LongHairStraight'
    player.c.avatar_settings.hair_color = '000000'
    player.c.avatar_settings.skin_color = 'fdbac3'
    player.c.avatar_settings.hair_type = 'short_flat' if sex == 'Male' else 'bob'
    player.c.avatar_settings.facial_hair = 'NONE'
    player.c.avatar_settings.accessory = 'NONE'
    player.c.avatar_settings.clothing = 'Hoodie'
    player.c.avatar_settings.mouth = 'Default'

    # Relationship attributes
    player.c.partner = None
    player.c.mother = None
    player.c.father = None
    player.c.siblings = []
    player.c.children = []

    player.type = "playerObject"

    return player
