package com.red.circle.other.app.command.dynamic.query;

import com.google.common.collect.Lists;
import com.red.circle.common.business.core.enums.SysOriginPlatformEnum;
import com.red.circle.common.business.dto.cmd.AppExtCommand;
import com.red.circle.other.app.dto.clientobject.dynamic.DynamicTagCO;
import com.red.circle.other.infra.database.rds.entity.dynamic.DynamicTag;
import com.red.circle.other.infra.database.rds.service.dynamic.DynamicTagService;
import com.red.circle.tool.core.collection.CollectionUtils;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * <p>
 * 动态标签列表.
 * </p>
 *
 * @author pengshigang
 * @since 2022-04-14
 */
@Component
@RequiredArgsConstructor
public class DynamicTagQryExe {

  private final DynamicTagService dynamicTagService;

  public List<DynamicTagCO> execute(AppExtCommand cmd) {

    List<DynamicTag> tags = dynamicTagService
        .listTag(SysOriginPlatformEnum.valueOf(cmd.getReqSysOrigin().getOrigin()),
            cmd.getReqLanguage());

    if (CollectionUtils.isEmpty(tags)) {
      return Lists.newArrayList();
    }

    return tags.stream().map(tag -> new DynamicTagCO()
        .setId(tag.getId())
        .setTag(tag.getTag())
        .setDesc(tag.getDescription())
        .setImageUrl(tag.getImageUrl())
    ).toList();
  }

}
