classdef firingRateMap < types.core.NWBDataInterface & types.untyped.GroupClass
% FIRINGRATEMAP Firing rate map attributes


% PROPERTIES
properties
    boundaries; % boundaries of firing rate map
    labels; % labels of firing rate map
    name; % name of firingRateMap
    x_bins; % bins of the firing rate map
end

methods
    function obj = firingRateMap(varargin)
        % FIRINGRATEMAP Constructor for firingRateMap
        %     obj = FIRINGRATEMAP(parentname1,parentvalue1,..,parentvalueN,parentargN,name1,value1,...,nameN,valueN)
        % name = char
        % boundaries = float
        % labels = char
        % x_bins = float
        obj = obj@types.core.NWBDataInterface(varargin{:});
        
        
        p = inputParser;
        p.KeepUnmatched = true;
        p.PartialMatching = false;
        p.StructExpand = false;
        addParameter(p, 'name',[]);
        addParameter(p, 'boundaries',[]);
        addParameter(p, 'labels',[]);
        addParameter(p, 'x_bins',[]);
        misc.parseSkipInvalidName(p, varargin);
        obj.name = p.Results.name;
        obj.boundaries = p.Results.boundaries;
        obj.labels = p.Results.labels;
        obj.x_bins = p.Results.x_bins;
        if strcmp(class(obj), 'types.ndx_cell_explorer.firingRateMap')
            types.util.checkUnset(obj, unique(varargin(1:2:end)));
        end
    end
    %% SETTERS
    function obj = set.boundaries(obj, val)
        obj.boundaries = obj.validate_boundaries(val);
    end
    function obj = set.labels(obj, val)
        obj.labels = obj.validate_labels(val);
    end
    function obj = set.name(obj, val)
        obj.name = obj.validate_name(val);
    end
    function obj = set.x_bins(obj, val)
        obj.x_bins = obj.validate_x_bins(val);
    end
    %% VALIDATORS
    
    function val = validate_boundaries(obj, val)
        val = types.util.checkDtype('boundaries', 'float', val);
        if isa(val, 'types.untyped.DataStub')
            valsz = val.dims;
        elseif istable(val)
            valsz = height(val);
        else
            valsz = size(val);
        end
        validshapes = {[Inf]};
        types.util.checkDims(valsz, validshapes);
    end
    function val = validate_labels(obj, val)
        val = types.util.checkDtype('labels', 'char', val);
    end
    function val = validate_name(obj, val)
        val = types.util.checkDtype('name', 'char', val);
    end
    function val = validate_x_bins(obj, val)
        val = types.util.checkDtype('x_bins', 'float', val);
        if isa(val, 'types.untyped.DataStub')
            valsz = val.dims;
        elseif istable(val)
            valsz = height(val);
        else
            valsz = size(val);
        end
        validshapes = {[Inf]};
        types.util.checkDims(valsz, validshapes);
    end
    %% EXPORT
    function refs = export(obj, fid, fullpath, refs)
        refs = export@types.core.NWBDataInterface(obj, fid, fullpath, refs);
        if any(strcmp(refs, fullpath))
            return;
        end
        if ~isempty(obj.boundaries)
            if startsWith(class(obj.boundaries), 'types.untyped.')
                refs = obj.boundaries.export(fid, [fullpath '/boundaries'], refs);
            elseif ~isempty(obj.boundaries)
                io.writeDataset(fid, [fullpath '/boundaries'], obj.boundaries, 'forceArray');
            end
        end
        if ~isempty(obj.labels)
            if startsWith(class(obj.labels), 'types.untyped.')
                refs = obj.labels.export(fid, [fullpath '/labels'], refs);
            elseif ~isempty(obj.labels)
                io.writeDataset(fid, [fullpath '/labels'], obj.labels);
            end
        end
        if ~isempty(obj.name)
            if startsWith(class(obj.name), 'types.untyped.')
                refs = obj.name.export(fid, [fullpath '/name'], refs);
            elseif ~isempty(obj.name)
                io.writeDataset(fid, [fullpath '/name'], obj.name);
            end
        else
            error('Property `name` is required in `%s`.', fullpath);
        end
        if ~isempty(obj.x_bins)
            if startsWith(class(obj.x_bins), 'types.untyped.')
                refs = obj.x_bins.export(fid, [fullpath '/x_bins'], refs);
            elseif ~isempty(obj.x_bins)
                io.writeDataset(fid, [fullpath '/x_bins'], obj.x_bins, 'forceArray');
            end
        end
    end
end

end