class CategoryConverterUseCase {
  constructor({ categoriesMapping }) {
    if (CategoryConverterUseCase.instance) {
      return CategoryConverterUseCase.instance;
    }

    this.categoriesMapping = categoriesMapping;
    CategoryConverterUseCase.instance = this;
  }

  execute(category) {
    const entry = this.categoriesMapping.find(item => item.id === category);

    return entry ? entry.related[0].split(', ').map(str => str.trim()) : null;
  }
}

module.exports = { CategoryConverterUseCase }