package com.ycwl.basic.image.pipeline.stages;

import com.ycwl.basic.image.pipeline.core.PhotoProcessContext;
import com.ycwl.basic.pipeline.core.StageResult;
import com.ycwl.basic.image.pipeline.enums.ImageType;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

/**
 * CleanupStage 单元测试
 */
class CleanupStageTest {

    @Test
    void testGetName() {
        CleanupStage stage = new CleanupStage();

        assertEquals("CleanupStage", stage.getName());
    }

    @Test
    void testGetPriority() {
        CleanupStage stage = new CleanupStage();

        assertEquals(999, stage.getPriority());
    }

    @Test
    void testShouldExecute_AlwaysTrue() {
        CleanupStage stage = new CleanupStage();

        PhotoProcessContext context = PhotoProcessContext.builder()
                .originalUrl("https://example.com/test.jpg")
                .scenicId(123L)
                .build();

        assertTrue(stage.shouldExecute(context));
    }

    @Test
    void testExecute_Success() {
        CleanupStage stage = new CleanupStage();

        PhotoProcessContext context = PhotoProcessContext.builder()
                .processId("test-cleanup")
                .originalUrl("https://example.com/test.jpg")
                .scenicId(123L)
                .build();

        StageResult result = stage.execute(context);

        assertTrue(result.isSuccess());
        assertNotNull(result.getMessage());
        assertTrue(result.getMessage().contains("已清理"));
    }

    @Test
    void testExecute_ForAllImageTypes() {
        CleanupStage stage = new CleanupStage();

        // 测试普通照片
        PhotoProcessContext normalContext = PhotoProcessContext.builder()
                .originalUrl("https://example.com/test.jpg")
                .scenicId(123L)
                .imageType(ImageType.NORMAL_PHOTO)
                .build();
        assertTrue(stage.execute(normalContext).isSuccess());

        // 测试拼图
        PhotoProcessContext puzzleContext = PhotoProcessContext.builder()
                .originalUrl("https://example.com/puzzle.png")
                .scenicId(123L)
                .imageType(ImageType.PUZZLE)
                .build();
        assertTrue(stage.execute(puzzleContext).isSuccess());

        // 测试手机上传
        PhotoProcessContext mobileContext = PhotoProcessContext.builder()
                .originalUrl("https://example.com/mobile.jpg")
                .scenicId(123L)
                .imageType(ImageType.MOBILE_UPLOAD)
                .build();
        assertTrue(stage.execute(mobileContext).isSuccess());
    }
}
