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

import org.junit.jupiter.api.Test;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import static org.junit.jupiter.api.Assertions.*;

/**
 * {@link TokenExpiresTimeTypeEnum} 的单元测试
 */
class TokenExpiresTimeTypeEnumTest {

    @Test
    void testEnumValues() {
        // 测试枚举值是否正确
        assertEquals("permanent", TokenExpiresTimeTypeEnum.PERMANENT.getType());
        assertEquals(99, TokenExpiresTimeTypeEnum.PERMANENT.getValue());
        assertEquals(ChronoUnit.FOREVER, TokenExpiresTimeTypeEnum.PERMANENT.getTimeType());
        assertEquals("永久", TokenExpiresTimeTypeEnum.PERMANENT.getName());

        assertEquals("1_hour", TokenExpiresTimeTypeEnum.ONEHOURS.getType());
        assertEquals(1, TokenExpiresTimeTypeEnum.ONEHOURS.getValue());
        assertEquals(ChronoUnit.HOURS, TokenExpiresTimeTypeEnum.ONEHOURS.getTimeType());
        assertEquals("1小时", TokenExpiresTimeTypeEnum.ONEHOURS.getName());


        assertEquals("1_day", TokenExpiresTimeTypeEnum.ONEDAYS.getType());
        assertEquals(1, TokenExpiresTimeTypeEnum.ONEDAYS.getValue());
        assertEquals(ChronoUnit.DAYS, TokenExpiresTimeTypeEnum.ONEDAYS.getTimeType());
        assertEquals("1天", TokenExpiresTimeTypeEnum.ONEDAYS.getName());

        assertEquals("15_day", TokenExpiresTimeTypeEnum.FIFTEENDAYS.getType());
        assertEquals(15, TokenExpiresTimeTypeEnum.FIFTEENDAYS.getValue());
        assertEquals(ChronoUnit.DAYS, TokenExpiresTimeTypeEnum.FIFTEENDAYS.getTimeType());
        assertEquals("15天", TokenExpiresTimeTypeEnum.FIFTEENDAYS.getName());

        assertEquals("1_month", TokenExpiresTimeTypeEnum.ONEMONTHS.getType());
        assertEquals(1, TokenExpiresTimeTypeEnum.ONEMONTHS.getValue());
        assertEquals(ChronoUnit.MONTHS, TokenExpiresTimeTypeEnum.ONEMONTHS.getTimeType());
        assertEquals("1个月", TokenExpiresTimeTypeEnum.ONEMONTHS.getName());

        assertEquals("6_month", TokenExpiresTimeTypeEnum.SIXMONTHS.getType());
        assertEquals(6, TokenExpiresTimeTypeEnum.SIXMONTHS.getValue());
        assertEquals(ChronoUnit.MONTHS, TokenExpiresTimeTypeEnum.SIXMONTHS.getTimeType());
        assertEquals("6个月", TokenExpiresTimeTypeEnum.SIXMONTHS.getName());
    }

    @Test
    void testAdjustTime() {
        LocalDateTime now = LocalDateTime.of(2023, 1, 1, 12, 0, 0);

        // 测试 adjustTime 方法
        assertEquals(LocalDateTime.of(2999, 1, 1, 0, 0, 0), 
            TokenExpiresTimeTypeEnum.adjustTime("permanent", now));

        assertEquals(now.plusHours(1), 
            TokenExpiresTimeTypeEnum.adjustTime("1_hour", now));

        assertEquals(now.plusHours(8), 
            TokenExpiresTimeTypeEnum.adjustTime("8_hour", now));

        assertEquals(now.plusHours(12), 
            TokenExpiresTimeTypeEnum.adjustTime("12_hour", now));

        assertEquals(now.plusDays(1), 
            TokenExpiresTimeTypeEnum.adjustTime("1_day", now));

        assertEquals(now.plusDays(7), 
            TokenExpiresTimeTypeEnum.adjustTime("7_day", now));

        assertEquals(now.plusDays(15), 
            TokenExpiresTimeTypeEnum.adjustTime("15_day", now));

        assertEquals(now.plusMonths(1), 
            TokenExpiresTimeTypeEnum.adjustTime("1_month", now));

        assertEquals(now.plusMonths(3), 
            TokenExpiresTimeTypeEnum.adjustTime("3_month", now));

        assertEquals(now.plusMonths(6), 
            TokenExpiresTimeTypeEnum.adjustTime("6_month", now));

        // 测试不存在的类型
        assertNull(TokenExpiresTimeTypeEnum.adjustTime("nonexistent", now));
        
        // 测试 null 类型
        assertNull(TokenExpiresTimeTypeEnum.adjustTime(null, now));
    }
}