package com.cf.imes.module.system.enums.social;

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

/**
 * {@link SocialTypeEnum} 的单元测试
 */
class SocialTypeEnumTest {

    @Test
    void testEnumValues() {
        // 测试枚举值是否正确
        assertEquals(10, SocialTypeEnum.GITEE.getType());
        assertEquals("GITEE", SocialTypeEnum.GITEE.getSource());

        assertEquals(20, SocialTypeEnum.DINGTALK.getType());
        assertEquals("DINGTALK", SocialTypeEnum.DINGTALK.getSource());

        assertEquals(30, SocialTypeEnum.WECHAT_ENTERPRISE.getType());
        assertEquals("WECHAT_ENTERPRISE", SocialTypeEnum.WECHAT_ENTERPRISE.getSource());

        assertEquals(31, SocialTypeEnum.WECHAT_MP.getType());
        assertEquals("WECHAT_MP", SocialTypeEnum.WECHAT_MP.getSource());

        assertEquals(32, SocialTypeEnum.WECHAT_OPEN.getType());
        assertEquals("WECHAT_OPEN", SocialTypeEnum.WECHAT_OPEN.getSource());

        assertEquals(34, SocialTypeEnum.WECHAT_MINI_APP.getType());
        assertEquals("WECHAT_MINI_APP", SocialTypeEnum.WECHAT_MINI_APP.getSource());
    }

    @Test
    void testArrays() {
        // 测试 ARRAYS 是否包含所有枚举值的类型
        int[] arrays = SocialTypeEnum.ARRAYS;
        assertEquals(6, arrays.length);
        assertTrue(contains(arrays, 10)); // GITEE
        assertTrue(contains(arrays, 20)); // DINGTALK
        assertTrue(contains(arrays, 30)); // WECHAT_ENTERPRISE
        assertTrue(contains(arrays, 31)); // WECHAT_MP
        assertTrue(contains(arrays, 32)); // WECHAT_OPEN
        assertTrue(contains(arrays, 34)); // WECHAT_MINI_APP
    }

    @Test
    void testArrayMethod() {
        // 测试array()方法
        int[] arrays = SocialTypeEnum.GITEE.array();
        assertEquals(6, arrays.length);
        assertTrue(contains(arrays, 10)); // GITEE
        assertTrue(contains(arrays, 20)); // DINGTALK
        assertTrue(contains(arrays, 30)); // WECHAT_ENTERPRISE
        assertTrue(contains(arrays, 31)); // WECHAT_MP
        assertTrue(contains(arrays, 32)); // WECHAT_OPEN
        assertTrue(contains(arrays, 34)); // WECHAT_MINI_APP
    }

    @Test
    void testValueOfType() {
        // 测试 valueOfType 方法
        assertEquals(SocialTypeEnum.GITEE, SocialTypeEnum.valueOfType(10));
        assertEquals(SocialTypeEnum.DINGTALK, SocialTypeEnum.valueOfType(20));
        assertEquals(SocialTypeEnum.WECHAT_ENTERPRISE, SocialTypeEnum.valueOfType(30));
        assertEquals(SocialTypeEnum.WECHAT_MP, SocialTypeEnum.valueOfType(31));
        assertEquals(SocialTypeEnum.WECHAT_OPEN, SocialTypeEnum.valueOfType(32));
        assertEquals(SocialTypeEnum.WECHAT_MINI_APP, SocialTypeEnum.valueOfType(34));
        assertNull(SocialTypeEnum.valueOfType(99)); // 不存在的类型
    }

    /**
     * 辅助方法：检查数组中是否包含指定元素
     *
     * @param array 数组
     * @param value 值
     * @return 是否包含
     */
    private boolean contains(int[] array, int value) {
        for (int item : array) {
            if (item == value) {
                return true;
            }
        }
        return false;
    }
}