""" HSUVision Class
"""
import sys
import numpy
from .params import *
from .msgs import *
from .contours import *


class HSUVision:
    """ There are three ways to use pre-defined comparable contours
        1. Use default saved contours from param
        Contours are Dictionaries, key is the letter name, value is the saved contour
        For custom contours one of two mentioned methods should be used as value in dictionary
        2. Use a string path to .npy files (Only use files which generated by saveSampleContours.py script
        3. Numpy ndarrays with (n,1,2) shape (n is the number of contour points)
    """

    def __init__(self, contours_dict= {'H': h_cnt, 'S': s_cnt, 'U': u_cnt}):
        if not isinstance(contours_dict, dict):
            raise TypeError(ref_contours_type_error)
        _cnts_dict = contours_dict.copy()
        for name, contour in _cnts_dict.items():
            if not ((isinstance(contour, str) and contour[-4:] == '.npy') or isinstance(contour, numpy.ndarray)):
                raise TypeError(ref_contour_type_error)
            elif isinstance(contour, str) and contour[-4:] == '.npy':
                _cnts_dict[name] = numpy.load(contour)
        self.ref_contours = _cnts_dict.copy()

    def find_HSU(self, img, verbose=False):
        return find_HSU(img, verbose, ref_contours=self.ref_contours)
