"""
This is the implementation of the OGN node defined in OgnMakeArrayDouble3.ogn
"""
import omni.graph.core as og


class OgnMakeArray:
    """
    Makes an output array attribute from input values
    """

    @staticmethod
    def compute(db) -> bool:
        """Compute the outputs from the current input"""
        if db.inputs.a.type.base_type == og.BaseDataType.UNKNOWN:
            return False

        array_size = db.inputs.arraySize
        out_array = []
        if array_size > 0:
            out_array.append(db.inputs.a.value)
        if array_size > 1:
            out_array.append(db.inputs.b.value)
        if array_size > 2:
            out_array.append(db.inputs.c.value)
        if array_size > 3:
            out_array.append(db.inputs.d.value)
        if array_size > 4:
            out_array.append(db.inputs.e.value)

        out_array.extend([db.inputs.e.value] * (array_size - 5))

        db.outputs.array.value = out_array
        return True

    @staticmethod
    def on_connection_type_resolve(node) -> None:
        attribs = [(node.get_attribute("inputs:" + a), None, 0, None) for a in ("a", "b", "c", "d", "e")]
        attribs.append((node.get_attribute("outputs:array"), None, 1, None))
        og.resolve_base_coupled(attribs)
