from typing import Any, Dict
from enum import Enum
import json

class GameCategory(Enum):
    BLACKJACK = 'casino_bj_game'
    SLOT = 'casino_slot_game'
    
    def __init__(self, table: str):
        self.table = table
    

class GameType(Enum):
    #BLACKJACK_MH = (348, 'blacjjack_mh', 'BlackJack MH', GameCategory.BLACKJACK)
    HOLIDAY_SEASON      = (318, 'holidayseason', 'Holiday Season', GameCategory.SLOT)
    MYSTERY_OF_EGYPT    = (1001, 'mysteryofegypt', 'Mystery of Egypt', GameCategory.SLOT)
    
    def __init__(self, id: int, code: str, game_name: str, category: GameCategory):
        self.id = id
        self.code = code
        self.game_name = game_name
        self.category = category
        
    @classmethod
    def by_code(cls, code):
        for item in cls:
            if item.code == code:
                return item
            
        return None

def extract_parse_json(input_str: str) -> Dict[str, Any]:
    first_brace = input_str.find('{')
    last_brace = input_str.rfind('}')

    if first_brace == -1 or last_brace == -1:
        print(f'JSON parsing error, input: {input_str}')
        return {}

    json_str = input_str[first_brace : last_brace + 1]
    if not json_str:
        print(f'JSON parsing error, input: {input_str}')
        return {}

    try:
        return json.loads(json_str)
    except Exception as e:
        print(f'JSON parsing error, input: {input_str}, error: {e}')
        return {}
    
    