package com.red.circle.other.app.dto.cmd.user.user;;

import com.red.circle.common.business.dto.cmd.AppExtCommand;
import com.red.circle.tool.core.text.StringUtils;
import com.red.circle.other.inner.model.cmd.user.account.MobileAuthCmd;
import com.red.circle.other.inner.enums.user.AuthTypeEnum;
import jakarta.validation.constraints.NotNull;
import java.util.Objects;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 绑定用户认证.
 *
 * @author pengliang on 2021/5/11
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class BindUserAuthTypeCmd extends AppExtCommand {

  /**
   * 认证类型.
   *
   * @eo.required
   */
  @NotNull(message = "type required")
  private AuthTypeEnum type;

  /**
   * 开发id.
   */
  private String openId;

  /**
   * 手机号码信息.
   */
  private MobileAuthCmd mobile;

  public boolean isTypeMobile() {
    return Objects.equals(type, AuthTypeEnum.MOBILE);
  }

  public String getActualOpenId() {

    if (!isTypeMobile() && StringUtils.isBlank(openId)) {
      return "";
    }

    return isTypeMobile()
        ? mobile.getFullPhoneNumber()
        : openId.concat("_").concat(requireReqSysOrigin());
  }

}
