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 com.ycwl.basic.image.watermark.enums.ImageWatermarkOperatorEnum;
import org.junit.jupiter.api.Test;

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

/**
 * WatermarkStage 单元测试
 */
class WatermarkStageTest {

    @Test
    void testGetName() {
        WatermarkConfig config = WatermarkConfig.builder().build();
        WatermarkStage stage = new WatermarkStage(config);

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

    @Test
    void testShouldExecute_NormalPhoto() {
        WatermarkConfig config = WatermarkConfig.builder()
                .watermarkType(ImageWatermarkOperatorEnum.PRINTER_DEFAULT)
                .build();
        WatermarkStage stage = new WatermarkStage(config);

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

        assertTrue(stage.shouldExecute(context));
    }

    @Test
    void testShouldExecute_Puzzle_ShouldSkip() {
        WatermarkConfig config = WatermarkConfig.builder()
                .watermarkType(ImageWatermarkOperatorEnum.PRINTER_DEFAULT)
                .build();
        WatermarkStage stage = new WatermarkStage(config);

        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() {
        WatermarkConfig config = WatermarkConfig.builder()
                .watermarkType(ImageWatermarkOperatorEnum.PRINTER_DEFAULT)
                .build();
        WatermarkStage stage = new WatermarkStage(config);

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

        assertFalse(stage.shouldExecute(context));
    }

    @Test
    void testExecute_NoWatermarkType_ShouldSkip() {
        // 创建没有 watermarkType 的配置
        WatermarkConfig config = WatermarkConfig.builder().build();
        WatermarkStage stage = new WatermarkStage(config);

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

        StageResult result = stage.execute(context);

        assertTrue(result.isSkipped());
        assertEquals("未配置水印", result.getMessage());
    }
}
