package com.kt.event.participation.test.unit;

import com.kt.event.participation.domain.draw.DrawLog;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.time.LocalDateTime;

import static org.assertj.core.api.Assertions.assertThat;

/**
 * DrawLog Entity 단위 테스트
 *
 * @author Digital Garage Team
 * @since 2025-01-24
 */
@DisplayName("DrawLog 엔티티 단위 테스트")
class DrawLogUnitTest {

    // 테스트 데이터 상수
    private static final String VALID_EVENT_ID = "evt_20250124_001";
    private static final Integer TOTAL_PARTICIPANTS = 100;
    private static final Integer WINNER_COUNT = 10;
    private static final String ALGORITHM = "WEIGHTED_RANDOM";
    private static final String DRAWN_BY = "admin";

    @Test
    @DisplayName("빌더로 추첨 로그를 생성하면 필드가 정상 설정된다")
    void givenValidData_whenBuild_thenDrawLogCreated() {
        // Given
        LocalDateTime drawnAt = LocalDateTime.now();

        // When
        DrawLog drawLog = DrawLog.builder()
                .eventId(VALID_EVENT_ID)
                .totalParticipants(TOTAL_PARTICIPANTS)
                .winnerCount(WINNER_COUNT)
                .applyStoreVisitBonus(true)
                .algorithm(ALGORITHM)
                .drawnAt(drawnAt)
                .drawnBy(DRAWN_BY)
                .build();

        // Then
        assertThat(drawLog.getEventId()).isEqualTo(VALID_EVENT_ID);
        assertThat(drawLog.getTotalParticipants()).isEqualTo(TOTAL_PARTICIPANTS);
        assertThat(drawLog.getWinnerCount()).isEqualTo(WINNER_COUNT);
        assertThat(drawLog.getApplyStoreVisitBonus()).isTrue();
        assertThat(drawLog.getAlgorithm()).isEqualTo(ALGORITHM);
        assertThat(drawLog.getDrawnAt()).isEqualTo(drawnAt);
        assertThat(drawLog.getDrawnBy()).isEqualTo(DRAWN_BY);
    }

    @Test
    @DisplayName("매장 방문 보너스 미적용으로 추첨 로그를 생성할 수 있다")
    void givenNoBonus_whenBuild_thenDrawLogCreated() {
        // Given
        LocalDateTime drawnAt = LocalDateTime.now();

        // When
        DrawLog drawLog = DrawLog.builder()
                .eventId(VALID_EVENT_ID)
                .totalParticipants(TOTAL_PARTICIPANTS)
                .winnerCount(WINNER_COUNT)
                .applyStoreVisitBonus(false)
                .algorithm(ALGORITHM)
                .drawnAt(drawnAt)
                .drawnBy(DRAWN_BY)
                .build();

        // Then
        assertThat(drawLog.getApplyStoreVisitBonus()).isFalse();
    }

    @Test
    @DisplayName("당첨자가 없는 경우도 추첨 로그를 생성할 수 있다")
    void givenNoWinners_whenBuild_thenDrawLogCreated() {
        // Given
        LocalDateTime drawnAt = LocalDateTime.now();
        Integer zeroWinners = 0;

        // When
        DrawLog drawLog = DrawLog.builder()
                .eventId(VALID_EVENT_ID)
                .totalParticipants(TOTAL_PARTICIPANTS)
                .winnerCount(zeroWinners)
                .applyStoreVisitBonus(true)
                .algorithm(ALGORITHM)
                .drawnAt(drawnAt)
                .drawnBy(DRAWN_BY)
                .build();

        // Then
        assertThat(drawLog.getWinnerCount()).isZero();
        assertThat(drawLog.getTotalParticipants()).isEqualTo(TOTAL_PARTICIPANTS);
    }
}
