import json
from typing import Any

import pygame

from Classes.System.Components.InputHandler import InputHandler

class MonsterCard(pygame.sprite.Sprite):
    __attacks = []
    __name:str
    __description:str
    __pos:pygame.Vector2
    __dragging:bool = False
    __offset:pygame.Vector2 = pygame.Vector2(0,0)
    __inputHandler: InputHandler
    __type:str = "MonsterCard"
    image:pygame.image
    rect:pygame.rect

    def __init__(self, pos:pygame.Vector2, assetDir:str, inputHandler:InputHandler):
        if assetDir == "":
            return ValueError.add_note("Card: imagePath cannot be empty")
        
        pygame.sprite.Sprite.__init__(self)

        data = json.load(open(assetDir + "/card.json"))
        self.__pos = pos
        self.__name = data["name"]
        self.image = pygame.image.load(assetDir + "/card.png").convert_alpha()
        self.rect = self.image.get_rect()
        self.dragging = False
        self.offset = pygame.Vector2(0, 0)  # Offset zwischen der Karte und der Mausposition
        self.__inputHandler = inputHandler
        self.rect.center = self.__pos
        self.__description = data["description"]
        self.original_size = self.image.get_size()
        self.original_position = self.rect.center

        for attack in data["attacks"]:
            self.__attacks.append(attack)

    def update(self):
        if self.getDragging():
            mouse_pos = self.__inputHandler.getMousePos()
            self.__pos = mouse_pos
            self.rect.center = self.__pos

    def attacks(self):
        return self.__attacks
    
    def getName(self) -> str:
        return self.__name

    def getCardSprite(self) -> pygame.image:
        return self.__cardSprite
    
    def getDescription(self):
        return self.__description

    def getDragging(self):
        return self.__dragging

    def getOffset(self):
        return self.__offset

    def getPos(self):
        return self.__pos

    def getType(self):
        return self.__type

    def setDragging(self, dragging:bool):
        self.__dragging = dragging

    def setOffset(self, offset:pygame.Vector2):
        self.__offset = offset

    def setPos(self, pos:pygame.Vector2):
        self.__pos = pos