# -*- coding: utf-8 -*-

"""
discopy error messages.
"""

import warnings


TYPE_ERROR = "Expected {}, got {} instead."
NOT_COMPOSABLE = "{} does not compose with {}: {} != {}."
NOT_PARALLEL = "Expected parallel arrows, got {} and {} instead."
NOT_ATOMIC = "Expected {} of length 1, got length {} instead."
NOT_CONNECTED = "{} is not boundary-connected."
NOT_TRACEABLE = "Cannot trace {} with {}."
NOT_ADJOINT = "{} and {} are not adjoints."
NOT_RIGID_ADJOINT = "{} is not the left adjoint of {}, maybe you meant to use"\
                    " a pivotal type rather than a rigid one?"
NOT_PREGROUP = "Expected a pregroup diagram of shape `word @ ... @ word "\
               ">> cups_and_swaps`, use diagram.draw() instead."
MISSING_TYPES_FOR_EMPTY_SUM = "Empty sum needs a domain and codomain."
MATRIX_TWO_DTYPES = "Matrix class cannot be indexed twice."
MATRIX_REPEAT_ERROR = "The reflexive transitive closure is only defined for "\
                      "square boolean matrices."
PROVIDE_CONTRACTOR = "Provide a contractor when using a non-numpy backend."
BOX_IS_MIXED = "Pure boxes can have only digits or only qudits as dom and cod."
LAYERS_MUST_BE_ODD = "Layers must have an odd number of boxes and types."
NOT_MERGEABLE = "Layers {} and {} cannot be merged."
INTERCHANGER_ERROR = "Boxes {} and {} do not commute."
WRONG_PERMUTATION = "Expected a permutation of length {}, got {}."
ZERO_DISTANCE_CONTROLLED = "Zero-distance controlled gates are ill-defined."
HAS_NO_ATTRIBUTE = "{!r} object has no attribute {!r}"


class WarnOnce:
    warned = False

    def __init__(self):
        self.warned = False

    def warn(self, message):
        if not self.warned:
            warnings.warn(message)
        self.warned = True
