package com.ycwl.basic.puzzle.util;

import com.ycwl.basic.puzzle.dto.ElementCreateRequest;
import org.junit.jupiter.api.Test;

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

class ElementConfigHelperTest {

    @Test
    void shouldAcceptImplementedElementType() {
        assertTrue(ElementConfigHelper.isValidElementType("TEXT"));
        assertTrue(ElementConfigHelper.isValidElementType("image"));
    }

    @Test
    void shouldRejectUnimplementedElementType() {
        assertFalse(ElementConfigHelper.isValidElementType("QRCODE"));

        ElementCreateRequest request = new ElementCreateRequest();
        request.setTemplateId(1L);
        request.setElementType("QRCODE");
        request.setElementKey("qr");
        request.setElementName("二维码");
        request.setXPosition(0);
        request.setYPosition(0);
        request.setWidth(100);
        request.setHeight(100);
        request.setConfig("{\"defaultText\":\"qr\"}");

        IllegalArgumentException ex = assertThrows(IllegalArgumentException.class,
                () -> ElementConfigHelper.validateRequest(request));
        assertTrue(ex.getMessage().contains("不支持的元素类型"));
    }
}
