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

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

/**
 * {@link SmsSceneEnum} 的单元测试
 */
class SmsSceneEnumTest {

    @Test
    void testEnumValues() {
        // 测试枚举值是否正确
        assertEquals(1, SmsSceneEnum.USER_UPDATE_MOBILE.getScene());
        assertEquals("user-update-mobile", SmsSceneEnum.USER_UPDATE_MOBILE.getTemplateCode());
        assertEquals("修改手机", SmsSceneEnum.USER_UPDATE_MOBILE.getDescription());

        assertEquals(2, SmsSceneEnum.USER_RESET_PASSWORD.getScene());
        assertEquals("user-reset-password", SmsSceneEnum.USER_RESET_PASSWORD.getTemplateCode());
        assertEquals("忘记密码", SmsSceneEnum.USER_RESET_PASSWORD.getDescription());

        assertEquals(3, SmsSceneEnum.USER_UPDATE_PASSWORD.getScene());
        assertEquals("user-update-password", SmsSceneEnum.USER_UPDATE_PASSWORD.getTemplateCode());
        assertEquals("修改密码", SmsSceneEnum.USER_UPDATE_PASSWORD.getDescription());

        assertEquals(4, SmsSceneEnum.USER_LOGIN_CAPTCHAVERIFICATION.getScene());
        assertEquals("user-login-captchaverification", SmsSceneEnum.USER_LOGIN_CAPTCHAVERIFICATION.getTemplateCode());
        assertEquals("登录验证码", SmsSceneEnum.USER_LOGIN_CAPTCHAVERIFICATION.getDescription());

        assertEquals(20, SmsSceneEnum.ADMIN_LOGIN.getScene());
        assertEquals("admin-sms-login", SmsSceneEnum.ADMIN_LOGIN.getTemplateCode());
        assertEquals("后台用户 - 手机号登录", SmsSceneEnum.ADMIN_LOGIN.getDescription());

        assertEquals(21, SmsSceneEnum.ADMIN_MEMBER_LOGIN.getScene());
        assertEquals("admin-sms-login", SmsSceneEnum.ADMIN_MEMBER_LOGIN.getTemplateCode());
        assertEquals("后台用户 - 手机号登录", SmsSceneEnum.ADMIN_MEMBER_LOGIN.getDescription());

        assertEquals(22, SmsSceneEnum.MEMBER_LOGIN.getScene());
        assertEquals("user-sms-login", SmsSceneEnum.MEMBER_LOGIN.getTemplateCode());
        assertEquals("会员用户 - 手机号登陆", SmsSceneEnum.MEMBER_LOGIN.getDescription());
    }

    @Test
    void testArrays() {
        // 测试 ARRAYS 是否包含所有枚举值的场景编号
        int[] arrays = SmsSceneEnum.ARRAYS;
        assertEquals(7, arrays.length);
        assertTrue(contains(arrays, 1)); // USER_UPDATE_MOBILE
        assertTrue(contains(arrays, 2)); // USER_RESET_PASSWORD
        assertTrue(contains(arrays, 3)); // USER_UPDATE_PASSWORD
        assertTrue(contains(arrays, 4)); // USER_LOGIN_CAPTCHAVERIFICATION
        assertTrue(contains(arrays, 20)); // ADMIN_LOGIN
        assertTrue(contains(arrays, 21)); // ADMIN_MEMBER_LOGIN
        assertTrue(contains(arrays, 22)); // MEMBER_LOGIN
    }

    @Test
    void testArrayMethod() {
        // 测试array()方法
        int[] arrays = SmsSceneEnum.USER_UPDATE_MOBILE.array();
        assertEquals(7, arrays.length);
        assertTrue(contains(arrays, 1)); // USER_UPDATE_MOBILE
        assertTrue(contains(arrays, 2)); // USER_RESET_PASSWORD
        assertTrue(contains(arrays, 3)); // USER_UPDATE_PASSWORD
        assertTrue(contains(arrays, 4)); // USER_LOGIN_CAPTCHAVERIFICATION
        assertTrue(contains(arrays, 20)); // ADMIN_LOGIN
        assertTrue(contains(arrays, 21)); // ADMIN_MEMBER_LOGIN
        assertTrue(contains(arrays, 22)); // MEMBER_LOGIN
    }

    @Test
    void testGetCodeByScene() {
        // 测试 getCodeByScene 方法
        assertEquals(SmsSceneEnum.USER_UPDATE_MOBILE, SmsSceneEnum.getCodeByScene(1));
        assertEquals(SmsSceneEnum.USER_RESET_PASSWORD, SmsSceneEnum.getCodeByScene(2));
        assertEquals(SmsSceneEnum.USER_UPDATE_PASSWORD, SmsSceneEnum.getCodeByScene(3));
        assertEquals(SmsSceneEnum.USER_LOGIN_CAPTCHAVERIFICATION, SmsSceneEnum.getCodeByScene(4));
        assertEquals(SmsSceneEnum.ADMIN_LOGIN, SmsSceneEnum.getCodeByScene(20));
        assertEquals(SmsSceneEnum.ADMIN_MEMBER_LOGIN, SmsSceneEnum.getCodeByScene(21));
        assertEquals(SmsSceneEnum.MEMBER_LOGIN, SmsSceneEnum.getCodeByScene(22));
        assertNull(SmsSceneEnum.getCodeByScene(99)); // 不存在的场景
    }

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