package com.starry.admin.modules.clerk.service.impl;

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

import com.starry.admin.modules.weichat.entity.clerk.MediaVo;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.junit.jupiter.api.Test;

class PlayClerkUserInfoServiceImplTest {

    @Test
    void mergeLegacyAlbumAppendsUniqueUrls() {
        List<String> legacy = Arrays.asList("https://oss/1.png", " ", "https://oss/2.png", "https://oss/1.png");
        List<MediaVo> destination = new ArrayList<>();
        MediaVo existing = new MediaVo();
        existing.setUrl("https://oss/2.png");
        destination.add(existing);

        List<MediaVo> merged = PlayClerkUserInfoServiceImpl.mergeLegacyAlbum(legacy, destination);

        assertThat(merged).hasSize(2);
        assertThat(merged.stream().map(MediaVo::getUrl))
                .containsExactlyInAnyOrder("https://oss/2.png", "https://oss/1.png");
    }

    @Test
    void mergeLegacyAlbumFillsUsageStatusAndReviewStateForLegacyEntries() {
        List<String> legacy = Arrays.asList("https://oss/legacy-only.png");
        List<MediaVo> destination = new ArrayList<>();

        List<MediaVo> merged = PlayClerkUserInfoServiceImpl.mergeLegacyAlbum(legacy, destination);

        assertThat(merged).hasSize(1);
        MediaVo legacyVo = merged.get(0);
        assertThat(legacyVo.getUrl()).isEqualTo("https://oss/legacy-only.png");
        assertThat(legacyVo.getId())
                .as("legacy media id should fallback to url for compatibility")
                .isEqualTo("https://oss/legacy-only.png");
        assertThat(legacyVo.getUsage()).isEqualTo(com.starry.admin.modules.clerk.enums.ClerkMediaUsage.PROFILE.getCode());
        assertThat(legacyVo.getStatus()).isEqualTo(com.starry.admin.modules.media.enums.MediaStatus.READY.getCode());
        assertThat(legacyVo.getReviewState())
                .isEqualTo(com.starry.admin.modules.clerk.enums.ClerkMediaReviewState.APPROVED.getCode());
    }
}
