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

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

import com.red.circle.other.domain.model.user.OwnSpecialId;
import com.red.circle.other.domain.model.user.UserProfile;
import com.red.circle.tool.core.date.TimestampUtils;
import org.junit.jupiter.api.Test;

class OnlineStatusUploadListenerTest {

  @Test
  void resolveActiveUserBitmapOffset_shouldUseNumericAccount() {
    UserProfile profile = new UserProfile();
    profile.setId(9988L);
    profile.setAccount("123456");

    assertEquals(123456L, OnlineStatusUploadListener.resolveActiveUserBitmapOffset(profile));
  }

  @Test
  void resolveActiveUserBitmapOffset_shouldFallbackToNumericSpecialAccount() {
    UserProfile profile = new UserProfile();
    profile.setId(9988L);
    profile.setAccount("abc");
    OwnSpecialId ownSpecialId = new OwnSpecialId();
    ownSpecialId.setAccount("654321");
    ownSpecialId.setExpiredTime(TimestampUtils.nowPlusDays(1));
    profile.setOwnSpecialId(ownSpecialId);

    assertEquals(654321L, OnlineStatusUploadListener.resolveActiveUserBitmapOffset(profile));
  }

  @Test
  void resolveActiveUserBitmapOffset_shouldFallbackToUserIdWhenAccountIsNotNumeric() {
    UserProfile profile = new UserProfile();
    profile.setId(9988L);
    profile.setAccount("abc");

    assertEquals(9988L, OnlineStatusUploadListener.resolveActiveUserBitmapOffset(profile));
  }

  @Test
  void resolveActiveUserBitmapOffset_shouldReturnNullWhenNoPositiveCandidateExists() {
    UserProfile profile = new UserProfile();
    profile.setId(0L);
    profile.setAccount("abc");

    assertNull(OnlineStatusUploadListener.resolveActiveUserBitmapOffset(profile));
  }
}
