# Simulation

class Simulation:
    def __init__(self):
        self.simulation = {
            "wages": {
                "name": "Average Wage",
                "desc": "Average earnings per hour.",
                "value": 3.24,
                "minval": 0,
                "maxval": None,
                "type": "economic",
            }
        }

        self.policy_effects = {
            "minimum_wage": "wages", 
        }

    def apply_policy(self, policy):
        policy_key = list(policy.keys())[0]
        if policy_key in self.policy_effects:
            sim_key = self.policy_effects[policy_key] 
            sim_data = self.simulation[sim_key]
            new_value = max(sim_data["minval"], policy[policy_key]["value"])

            if sim_data["maxval"] is not None:
                new_value = min(sim_data["maxval"], new_value)

            sim_data["value"] = new_value

# Policies

class Policies:
    def __init__(self):
        self.policies = {
            "minimum_wage": {
                "name": "Minimum Wage",
                "desc": "Legal minimum wage employers must pay out.",
                "active": False,
                "value": 7,
                "minval": 0,
                "maxval": None,
                "type": "economic",
            },
        }

    def apply_policies(self, sim):
        """Applies all active policies to the simulation."""
        for policy_key, policy_data in self.policies.items():
            if policy_data["active"]:
                sim.apply_policy({policy_key: policy_data})

# Turn Calculation

class Turns:
   pass

# Gamestate

class GameState:
    def __init__(self):
        self.sim = Simulation()
        self.pol = Policies()
        self.turns = Turns()
        
        self.commands={ # Creates the commands dictionary.
            "SOCIAL": social,
            "ECONOMIC": economic,
            "POLITICAL": political,
            "FOREIGN": foreign,
            "QUIT": return_menu,
            "DEV": developer,
        }

        self.is_running = True  # Is game running? True!
        self.in_menu = True  # Is game in menu? True!

def main(): # Main menu. Barebones. Will eventually require a rehaul with new game, load game, options, etc.
    game_state = GameState()
    while game_state.in_menu:
        print("""
 ________________
|                |
|                |
|    WELCOME     |
|                |
|________________|
        """)
        print("Please select an option:")
        print("[1]: Start Game")
        print("[2]: Exit Game")
        try:
            command = int(input("Write the option you want: \n"))
            match command:
                case 1:
                    print("Welcome!")
                    start_game(game_state)
                    game_state.is_running=True
                case 2:
                    print("Goodbye!")
                    game_state.in_menu = False
                case _:
                    print("That number does not work. Please try again.")
        except ValueError:
            print("Error!")

def start_game(game_state): # Prints the start game text. Any important pre-gameloop stages will be set here if any come up..
  print("""WELCOME TO THE GAME. THIS SECTION WILL EVENTUALLY HAVE COUNTRY SELECTION.""")
  game_loop(game_state)

def game_loop(game_state): # Core came loop. Prints location name, all possible commands. Simple. Clean. Beautiful.
    while game_state.is_running:
        print(f"\nWelcome back, leader.")
        print("[SOCIAL] SPHERE")
        print("[ECONOMIC] SPHERE")
        print("[POLITICAL] SPHERE")
        print("[FOREIGN] SPHERE")
        print("[QUIT]: Return to Main Menu")
        try:
            command = input("Select option: \n").upper()
            if command in game_state.commands:
                if game_state.commands[command]:
                    game_state.commands[command](game_state)
            else:
                print("Unknown command. Try again.")
        except ValueError:
            print("Error!")

def social(game_state):
    while game_state.is_running:
        print(f"\nWelcome to the Social Sphere, leader.")
        print("[SOCIAL] SPHERE")
        print("[ECONOMIC] SPHERE")
        print("[POLITICAL] SPHERE")
        print("[FOREIGN] SPHERE")
        print("[QUIT]: Return to Main Menu")
        try:
            command = input("Select option: \n").upper()
            if command in game_state.commands:
                if game_state.commands[command]:
                    game_state.commands[command](game_state)
            else:
                print("Unknown command. Try again.")
        except ValueError:
            print("Error!")

def economic(game_state):
    while game_state.is_running:
        print(f"\nWelcome to the Economic Sphere, leader.")
        print("[SOCIAL] SPHERE")
        print("[ECONOMIC] SPHERE")
        print("[POLITICAL] SPHERE")
        print("[FOREIGN] SPHERE")
        print("[QUIT]: Return to Main Menu")
        try:
            command = input("Select option: \n").upper()
            if command in game_state.commands:
                if game_state.commands[command]:
                    game_state.commands[command](game_state)
            else:
                print("Unknown command. Try again.")
        except ValueError:
            print("Error!")

def political(game_state):
    while game_state.is_running:
        print(f"\nWelcome Politcal Sphere, leader.")
        print("[SOCIAL] SPHERE")
        print("[ECONOMIC] SPHERE")
        print("[POLITICAL] SPHERE")
        print("[FOREIGN] SPHERE")
        print("[QUIT]: Return to Main Menu")
        try:
            command = input("Select option: \n").upper()
            if command in game_state.commands:
                if game_state.commands[command]:
                    game_state.commands[command](game_state)
            else:
                print("Unknown command. Try again.")
        except ValueError:
            print("Error!")

def foreign(game_state):
    while game_state.is_running:
        print(f"\nWelcome Foreign Sphere, leader.")
        print("[SOCIAL] SPHERE")
        print("[ECONOMIC] SPHERE")
        print("[POLITICAL] SPHERE")
        print("[FOREIGN] SPHERE")
        print("[QUIT]: Return to Main Menu")
        try:
            command = input("Select option: \n").upper()
            if command in game_state.commands:
                if game_state.commands[command]:
                    game_state.commands[command](game_state)
            else:
                print("Unknown command. Try again.")
        except ValueError:
            print("Error!")

def developer(game_state): # Developer console.
    while True:
        print(f"DEV CONSOLE BABY")
        try:
            command = input("DEV DEV DEV\n").upper()
            match command:
                case "BACK":
                    return
                case _:
                    print("Unknown command. Try again.")
        except ValueError:
            print("Error!")

def return_menu(game_state): # Returns properly to the main menu without any error. Will in the future allow for saving.
    game_state.is_running = False
    game_state.in_menu = True

main()