"""Global configuration options for cv3.

This module provides global configuration options that affect the behavior
of various functions in the cv3 library. These options can be modified
directly or through provided setter functions.

Attributes:
    RGB (bool): Flag indicating whether to use RGB color format (True) or BGR (False).
    FPS (int): Default frames per second for video operations.
    FOURCC (str or int): Default codec for video writing.
    THICKNESS (int): Default line thickness for drawing operations.
    COLOR: Default color for drawing operations.
    FONT: Default font for text drawing operations.
    SCALE (float): Default scale factor for drawing operations.
    PT_RADIUS (int): Default point radius for drawing operations.
    EXPERIMENTAL (bool): Flag to enable experimental features.
"""
import cv2
import numpy as np

RGB = True
FPS = 30
FOURCC = 'mp4v'
THICKNESS = 1
COLOR = 255
FONT = cv2.FONT_HERSHEY_SIMPLEX
SCALE = 1
PT_RADIUS = 1
EXPERIMENTAL = False

def set_rgb():
    """Set the color format to RGB.
    
    This function sets the global RGB flag to True, indicating that
    color values should be interpreted as RGB rather than BGR.
    """
    global RGB
    RGB = True


def set_bgr():
    """Set the color format to BGR.
    
    This function sets the global RGB flag to False, indicating that
    color values should be interpreted as BGR rather than RGB.
    """
    global RGB
    RGB = False


def video(fps=None, fourcc=None):
    """Set default video parameters.
    
    Args:
        fps (int, optional): Default frames per second for video operations.
        fourcc (str or int, optional): Default codec for video writing.
        
    Raises:
        AssertionError: If fps is not positive.
    """
    global FPS, FOURCC
    if fps is not None:
        assert fps > 0, 'default fps must be more 0'
        FPS = fps
    if fourcc is not None:
        # TODO asserts flags
        FOURCC = cv2.VideoWriter_fourcc(*fourcc) if isinstance(fourcc, str) else fourcc


def draw(thickness=None, color=None, font=None, pt_radius=None, scale=None, line_type=None):
    """Set default drawing parameters.
    
    Args:
        thickness (int, optional): Default line thickness for drawing operations.
        color (optional): Default color for drawing operations.
        font (optional): Default font for text drawing operations.
        pt_radius (int, optional): Default point radius for drawing operations.
        scale (float, optional): Default scale factor for drawing operations.
        line_type (optional): Default line type for drawing operations.
        
    Raises:
        AssertionError: If thickness is not a positive integer.
        AssertionError: If color is not of a supported type.
    """
    global THICKNESS, COLOR, FONT, PT_RADIUS, SCALE, LINE_TYPE
    if thickness is not None:
        assert isinstance(thickness, (int, np.unsignedinteger)), 'default thickness must be positive integer'
        THICKNESS = thickness
    if color is not None:
        assert isinstance(color, (str, int, float, np.unsignedinteger, np.floating, np.ndarray, list, tuple))
        COLOR = color
    if font is not None:
        # TODO asserts flags
        FONT = font
    if pt_radius is not None:
        # TODO asserts
        PT_RADIUS = pt_radius
    if scale is not None:
        # TODO asserts
        SCALE = scale
    if line_type is not None:
        # TODO asserts flags
        LINE_TYPE = line_type
