module BrayniacAI
  class Tag < Base
    def to_a
      [faces_list, labels_list, texts_list].concat.flatten
    end

    private

    CATEGORIES = %w( AgeRange Gender )
    BOOLEAN_CATEGORIES = %w( Beard Mustache Eyeglasses Sunglasses )

    def faces_list
      [].tap do |tags|
        # Add the value of the category to the tags
        tags.append convert_category_values_to_array CATEGORIES
        
        # If the value for the category is true, add that category name to the tags
        tags.append convert_category_booleans_to_array BOOLEAN_CATEGORIES
      end
    end

    def labels_list
      labels
    end

    def texts_list
      text.map { |tag| tag.text }.uniq
    end

    def convert_category_values_to_array(categories)
      categories.map do |category|
        Array.wrap(faces.try(category)).map do |value|
          value.titleize
        end
      end.flatten
    end

    def convert_category_booleans_to_array(categories)
      categories.map do |category|
        category if faces.try(category)
      end.compact
    end
  end
end
