package com.red.circle.other.app.listener.strategy;

import com.red.circle.mq.business.model.event.approval.ApprovalEvent;
import com.red.circle.other.domain.gateway.user.UserProfileGateway;
import com.red.circle.tool.core.text.StringUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 个人资料签名审核
 *
 * @author pengliang on 2020/12/10
 */
@Slf4j
@Component("PROFILE_DESC_APPROVAL")
@RequiredArgsConstructor
public class ProfileDescStrategy implements ApprovalStrategy {

  private final UserProfileGateway userProfileGateway;

  @Override
  public void doOperation(ApprovalEvent param) {
    if (param.approvalNotPass()) {
      // 清空签名
      userProfileGateway.updateBatchUserAutographEmpty(param.waitApprovalUserIds());
      param.setWaitApprovalUser(param.getWaitApprovalUser().stream().peek(approvalUserParam -> {
        if (StringUtils.isNotBlank(approvalUserParam.getContent())) {
          approvalUserParam.setContent(approvalUserParam.getContent() + " #替换# ''");
        }
      }).toList());

    }
  }
}
