import json
from .event_args import EventArgs
from typing import Any


class CapturePhotoArgs(EventArgs):

    extra_fields: dict[str, Any]

    def __init__(
        self,
        height: int = 0,
        width: int = 0,
        interval_seconds: float = 0.0,
        quality: int = 93,
        encoding: str = 'jpg',
        vflip: int = 0,
        hflip: int = 0,
        rotation: int = 0,
        brightness: float = 0.0,
        contrast: float = 1.0,
        saturation: float = 1.0,
        sharpness: float = 1.0,
        awb: str = 'auto',
        exposure: str = 'normal',
        ev: float = 0.0,
        denoise: str = 'auto',
        shutter: int = 0,
        gain: float = 0.0,
        hdr: str = 'off',
        **kwargs: Any
    ):
        self.height = height
        self.width = width
        self.interval_seconds = interval_seconds
        self.quality = quality
        self.encoding = encoding
        self.vflip = vflip
        self.hflip = hflip
        self.rotation = rotation
        self.brightness = brightness
        self.contrast = contrast
        self.saturation = saturation
        self.sharpness = sharpness
        self.awb = awb
        self.exposure = exposure
        self.ev = ev
        self.denoise = denoise
        self.shutter = shutter
        self.gain = gain
        self.hdr = hdr

        camel_to_snake = {
            "intervalSeconds": "interval_seconds",
        }

        for camel_key, snake_key in camel_to_snake.items():
            if camel_key in kwargs:
                setattr(self, snake_key, kwargs.pop(camel_key))

        self.extra_fields = kwargs

        if kwargs:
            print(f"Extra fields: {kwargs}")

    def to_dict(self):
        return {
            "height": self.height,
            "width": self.width,
            "intervalSeconds": self.interval_seconds,
            "quality": self.quality,
            "encoding": self.encoding,
            "vflip": self.vflip,
            "hflip": self.hflip,
            "rotation": self.rotation,
            "brightness": self.brightness,
            "contrast": self.contrast,
            "saturation": self.saturation,
            "sharpness": self.sharpness,
            "awb": self.awb,
            "exposure": self.exposure,
            "ev": self.ev,
            "denoise": self.denoise,
            "shutter": self.shutter,
            "gain": self.gain,
            "hdr": self.hdr,
        }

    def to_json(self):
        return json.dumps(self.to_dict())