import json
from typing import Any


class Image:

    extra_fields: dict[str, Any]

    def __init__(
        self,
        key: int = 0,
        user_id: int = 0,
        device_id: int = 0,
        file_id: int = 0,
        image_status: int = 0,
        image_type_id: int = 0,
        local_file_path: str = '',
        height: int = 0,
        width: int = 0,
        file_size: int = 0,
        start_time: int = 0,
        start_time_ms: int = 0,
        tag_list_id: int = 0,
        creation_date: str = '',
        created_by: int = 0,
        last_modified_date: str = '',
        last_modified_by: int = 0,
        **kwargs: Any
    ):
        self.key = key
        self.user_id = user_id
        self.device_id = device_id
        self.file_id = file_id
        self.image_status = image_status
        self.image_type_id = image_type_id
        self.local_file_path = local_file_path
        self.height = height
        self.width = width
        self.file_size = file_size
        self.start_time = start_time
        self.start_time_ms = start_time_ms
        self.tag_list_id = tag_list_id
        self.creation_date = creation_date
        self.created_by = created_by
        self.last_modified_date = last_modified_date
        self.last_modified_by = last_modified_by

        camel_to_snake = {
            "userID": "user_id",
            "deviceID": "device_id",
            "fileID": "file_id",
            "imageStatus": "image_status",
            "imageTypeID": "image_type_id",
            "localFilePath": "local_file_path",
            "filesize": "file_size",
            "startTime": "start_time",
            "startTimeMs": "start_time_ms",
            "tagListID": "tag_list_id",
            "creationDate": "creation_date",
            "createdBy": "created_by",
            "lastModifiedDate": "last_modified_date",
            "lastModifiedBy": "last_modified_by",
        }

        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 {
            "key": self.key,
            "userID": self.user_id,
            "deviceID": self.device_id,
            "fileID": self.file_id,
            "imageStatus": self.image_status,
            "imageTypeID": self.image_type_id,
            "localFilePath": self.local_file_path,
            "height": self.height,
            "width": self.width,
            "filesize": self.file_size,
            "startTime": self.start_time,
            "startTimeMs": self.start_time_ms,
            "tagListID": self.tag_list_id,
            "creationDate": self.creation_date,
            "createdBy": self.created_by,
            "lastModifiedDate": self.last_modified_date,
            "lastModifiedBy": self.last_modified_by,
        }

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