from importlib.resources import files

import numpy as np

from .. import RELAIData


class Array2D(RELAIData):
    """Data model for a 2D array.

    Args:
        array (np.ndarray): 2D array to be stored.
    """

    schema_file: str = files("relai_visualization").joinpath("schema/data/2D-array.schema.json")

    def __init__(self, array: np.ndarray) -> None:
        if array.ndim != 2:
            raise ValueError("Array must be 2D.")
        if not np.issubdtype(array.dtype, np.number):
            raise ValueError("Array must be numeric.")
        if array.size == 0:
            raise ValueError("Array must not be empty.")
        super().__init__(data=array.tolist())
