from collections import defaultdict

import distinctipy


def reverse_dict(input_dict):
    reversed_dict = defaultdict(list)
    for key, value in input_dict.items():
        reversed_dict[value].append(key)
    return dict(reversed_dict)


def rgb_to_hex(rgb_color):
    """Convert RGB tuple to hex color. Generated by GPT-4 OMNI."""
    return "#{:02x}{:02x}{:02x}".format(
        int(rgb_color[0] * 255), int(rgb_color[1] * 255), int(rgb_color[2] * 255)
    )


def generate_complementary_colors(k):
    """
    Generate a list of k visually distinct complementary colors.
    Generated by GPT-4 OMNI.

    Parameters:
    k (int): Number of complementary colors to generate.

    Returns:
    List[str]: List of hex color codes.
    """
    # Generate k visually distinct colors
    colors = distinctipy.get_colors(k, pastel_factor=0.9)

    # Convert the RGB tuples to hex color codes
    hex_colors = [rgb_to_hex(color) for color in colors]

    return hex_colors
