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

/**
 * PuzzleBorderStage 单元测试
 */
class PuzzleBorderStageTest {

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

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

    @Test
    void testShouldExecute_Puzzle() {
        PuzzleBorderStage stage = new PuzzleBorderStage();

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

        assertTrue(stage.shouldExecute(context));
    }

    @Test
    void testShouldExecute_NormalPhoto_ShouldSkip() {
        PuzzleBorderStage stage = new PuzzleBorderStage();

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

        assertFalse(stage.shouldExecute(context));
    }

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

        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() {
        PuzzleBorderStage stage = new PuzzleBorderStage();

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

        StageResult result = stage.execute(context);

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