package cn.novalon.gym.manage.sys.core.domain;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.time.LocalDateTime;

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

class SysUserTest {

    private SysUser user;

    @BeforeEach
    void setUp() {
        user = new SysUser();
    }

    @Test
    void testGenerateId() {
        Long id = user.generateId();

        assertNotNull(id);
        assertTrue(id > 0);
        assertEquals(id, user.getId());
    }

    @Test
    void testGenerateId_GeneratesUniqueIds() {
        SysUser user1 = new SysUser();
        SysUser user2 = new SysUser();

        Long id1 = user1.generateId();
        Long id2 = user2.generateId();

        assertNotNull(id1);
        assertNotNull(id2);
        assertNotEquals(id1, id2);
    }

    @Test
    void testDelete() {
        assertNull(user.getDeletedAt());

        user.delete();

        assertNotNull(user.getDeletedAt());
        assertTrue(user.getDeletedAt().isBefore(LocalDateTime.now().plusSeconds(1)));
        assertTrue(user.getDeletedAt().isAfter(LocalDateTime.now().minusSeconds(1)));
    }

    @Test
    void testDelete_WhenAlreadyDeleted() {
        user.delete();
        LocalDateTime firstDeleteTime = user.getDeletedAt();

        user.delete();
        LocalDateTime secondDeleteTime = user.getDeletedAt();

        assertNotNull(firstDeleteTime);
        assertNotNull(secondDeleteTime);
        assertEquals(firstDeleteTime, secondDeleteTime);
    }

    @Test
    void testUsername() {
        user.setUsername("testuser");
        assertEquals("testuser", user.getUsername());
    }

    @Test
    void testPassword() {
        user.setPassword("password123");
        assertEquals("password123", user.getPassword());
    }

    @Test
    void testNickname() {
        user.setNickname("测试用户");
        assertEquals("测试用户", user.getNickname());
    }

    @Test
    void testEmail() {
        user.setEmail("test@example.com");
        assertEquals("test@example.com", user.getEmail());
    }

    @Test
    void testPhone() {
        user.setPhone("13800138000");
        assertEquals("13800138000", user.getPhone());
    }

    @Test
    void testRoleId() {
        user.setRoleId(1L);
        assertEquals(1L, user.getRoleId());
    }

    @Test
    void testStatus() {
        user.setStatus(1);
        assertEquals(1, user.getStatus());
    }
}
