package com.red.circle.other.app.command.user;

import com.red.circle.common.business.dto.cmd.app.AppUserIdCmd;
import com.red.circle.other.domain.model.user.ability.UserRelationsCalculator;
import com.red.circle.other.domain.model.user.ability.UserRelationsCalculator.CounterEnum;
import com.red.circle.other.domain.gateway.user.ability.UserRelationsCalculatorGateway;
import com.red.circle.other.infra.database.rds.service.user.user.RelationshipFriendService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 移除好友关系.
 *
 * @author pengliang on 2021/5/7
 */
@Component
@RequiredArgsConstructor
public class FriendRemoveCmdExe {

  private final RelationshipFriendService relationshipFriendService;
  private final UserRelationsCalculatorGateway userRelationsCalculatorGateway;

  public void execute(AppUserIdCmd cmd) {
    relationshipFriendService.removeFriend(cmd.requiredReqUserId(), cmd.getUserId());
    userRelationsCalculatorGateway.process(new UserRelationsCalculator()
        .setUserId(cmd.requiredReqUserId())
        .setSubUserId(cmd.getUserId())
        .setIncr(Boolean.FALSE)
        .setType(CounterEnum.FRIEND)
    );
  }

}
