from typing import Optional
from konabot.plugins.fx_process.fx_handle import ImageFilterEmpty, ImageFilterImplement, ImageFilterStorage

class ImageFilterManager:
    filter_map = {
        "模糊": ImageFilterImplement.apply_blur,
        "马赛克": ImageFilterImplement.apply_mosaic,
        "轮廓": ImageFilterImplement.apply_contour,
        "锐化": ImageFilterImplement.apply_sharpen,
        "边缘增强": ImageFilterImplement.apply_edge_enhance,
        "浮雕": ImageFilterImplement.apply_emboss,
        "查找边缘": ImageFilterImplement.apply_find_edges,
        "平滑": ImageFilterImplement.apply_smooth,
        "反色": ImageFilterImplement.apply_invert,
        "黑白": ImageFilterImplement.apply_black_white,
        "阈值": ImageFilterImplement.apply_threshold,
        "对比度": ImageFilterImplement.apply_contrast,
        "亮度": ImageFilterImplement.apply_brightness,
        "色彩": ImageFilterImplement.apply_color,
        "色调": ImageFilterImplement.apply_to_color,
        "缩放": ImageFilterImplement.apply_resize,
        "波纹": ImageFilterImplement.apply_wave,
        "色键": ImageFilterImplement.apply_color_key,
        "暗角": ImageFilterImplement.apply_vignette,
        "发光": ImageFilterImplement.apply_glow,
        "RGB分离": ImageFilterImplement.apply_rgb_split,
        "光学补偿": ImageFilterImplement.apply_optical_compensation,
        "球面化": ImageFilterImplement.apply_spherize,
        "旋转": ImageFilterImplement.apply_rotate,
        "透视变换": ImageFilterImplement.apply_perspective_transform,
        "裁剪": ImageFilterImplement.apply_crop,
        "噪点": ImageFilterImplement.apply_noise,
        "平移": ImageFilterImplement.apply_translate,
        "拓展边缘": ImageFilterImplement.apply_expand_edges,
        "素描": ImageFilterImplement.apply_sketch,
        "叠加颜色": ImageFilterImplement.apply_gradient_overlay,
        "阴影": ImageFilterImplement.apply_shadow,
        "径向模糊": ImageFilterImplement.apply_radial_blur,
        "旋转模糊": ImageFilterImplement.apply_spin_blur,
        "方向模糊": ImageFilterImplement.apply_directional_blur,
        "边缘模糊": ImageFilterImplement.apply_focus_blur,
        "缩放模糊": ImageFilterImplement.apply_zoom_blur,
        "镜像": ImageFilterImplement.apply_mirror_half,
        "水平翻转": ImageFilterImplement.apply_flip_horizontal,
        "垂直翻转": ImageFilterImplement.apply_flip_vertical,
        "复制": ImageFilterImplement.copy_area,
        "晃动": ImageFilterImplement.apply_random_wiggle,
        "动图": ImageFilterEmpty.empty_filter_param,
        "像素抖动": ImageFilterImplement.apply_pixel_jitter,
        "描边": ImageFilterImplement.apply_stroke,
        "形状描边": ImageFilterImplement.apply_shape_stroke,
        "半调": ImageFilterImplement.apply_halftone,
        "JPEG损坏": ImageFilterImplement.apply_jpeg_damage,
        "设置通道": ImageFilterImplement.apply_set_channel,
        "设置遮罩": ImageFilterImplement.apply_set_mask,
        # 图像处理
        "存入图像": ImageFilterStorage.store_image,
        "读取图像": ImageFilterStorage.load_image,
        "暂存图像": ImageFilterStorage.temp_store_image,
        "交换图像": ImageFilterStorage.swap_image_index,
        "删除图像": ImageFilterStorage.delete_image_by_index,
        "选择图像": ImageFilterStorage.select_image_by_index,
        # 多图像处理
        "混合图像": ImageFilterImplement.apply_blend,
        "覆盖图像": ImageFilterImplement.apply_overlay,
        # 生成式
        "覆加颜色": ImageFilterImplement.generate_solid,
        # Pixel Sort
        "像素排序": ImageFilterImplement.apply_pixel_sort,
    }

    generate_filter_map = {
        "生成图层": ImageFilterImplement.generate_empty,
        "生成文本": ImageFilterImplement.generate_text
    }

    @classmethod
    def get_filter(cls, name: str) -> Optional[callable]:
        if name in cls.filter_map:
            return cls.filter_map[name]
        elif name in cls.generate_filter_map:
            return cls.generate_filter_map[name]
        else:
            return None
    
    @classmethod
    def has_filter(cls, name: str) -> bool:
        return name in cls.filter_map or name in cls.generate_filter_map
    
    