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

import com.red.circle.other.app.dto.cmd.material.SwitchUsePropsCmd;
import com.red.circle.other.domain.gateway.user.UserProfileGateway;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 用户切换使用道具.
 *
 * @author pengliang on 2021/1/23
 */
@Component
@RequiredArgsConstructor
public class UserSwitchUsePropsCmdExe {

  private final UserProfileGateway userProfileGateway;

  public void execute(SwitchUsePropsCmd cmd) {
    if (Objects.equals(cmd.getUnload(), Boolean.TRUE)) {
      userProfileGateway.removeUseProps(
          cmd.requiredReqUserId(),
          Objects.toString(cmd.getType())
      );
      return;
    }
    userProfileGateway.switchUseProps(
        cmd.requiredReqUserId(),
        cmd.getPropsId()
    );
  }


}
