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.*;

/**
 * ImageQualityCheckStage 单元测试
 */
class ImageQualityCheckStageTest {

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

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

    @Test
    void testShouldExecute_NormalPhoto() {
        ImageQualityCheckStage stage = new ImageQualityCheckStage();

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

        // ImageQualityCheckStage 默认不启用，需要显式启用
        context.loadStageConfig(null, java.util.Map.of("quality_check", true));

        assertTrue(stage.shouldExecute(context));
    }

    @Test
    void testShouldExecute_Puzzle_ShouldSkip() {
        ImageQualityCheckStage stage = new ImageQualityCheckStage();

        PhotoProcessContext context = PhotoProcessContext.builder()
                .originalUrl("https://example.com/puzzle.png")
                .scenicId(123L)
                .imageType(ImageType.PUZZLE)
                .build();

        assertFalse(stage.shouldExecute(context));
    }

    @Test
    void testShouldExecute_MobileUpload_ShouldSkip() {
        ImageQualityCheckStage stage = new ImageQualityCheckStage();

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

        assertFalse(stage.shouldExecute(context));
    }

    @Test
    void testExecute_NoCurrentFile_ShouldFail() {
        ImageQualityCheckStage stage = new ImageQualityCheckStage();

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

        StageResult result = stage.execute(context);

        assertTrue(result.isFailed());
        assertEquals("当前文件不存在", result.getMessage());
    }
}
