package cn.novalon.manage.sys.dto.response;

import cn.novalon.manage.sys.core.domain.SysUser;
import org.junit.jupiter.api.Test;

import java.time.LocalDateTime;

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

class UserResponseTest {

    @Test
    void testGettersAndSetters() {
        UserResponse response = new UserResponse();
        
        response.setId(1L);
        response.setUsername("testuser");
        response.setEmail("test@example.com");
        response.setRoleId(2L);
        response.setStatus(1);
        response.setCreatedAt(LocalDateTime.now());
        response.setUpdatedAt(LocalDateTime.now());

        assertEquals(1L, response.getId());
        assertEquals("testuser", response.getUsername());
        assertEquals("test@example.com", response.getEmail());
        assertEquals(2L, response.getRoleId());
        assertEquals(1, response.getStatus());
        assertNotNull(response.getCreatedAt());
        assertNotNull(response.getUpdatedAt());
    }

    @Test
    void testFromDomain() {
        SysUser user = new SysUser();
        user.setId(1L);
        user.setUsername("testuser");
        user.setEmail("test@example.com");
        user.setRoleId(2L);
        user.setStatus(1);
        user.setCreatedAt(LocalDateTime.now());
        user.setUpdatedAt(LocalDateTime.now());

        UserResponse response = UserResponse.fromDomain(user);

        assertEquals(user.getId(), response.getId());
        assertEquals(user.getUsername(), response.getUsername());
        assertEquals(user.getEmail(), response.getEmail());
        assertEquals(user.getRoleId(), response.getRoleId());
        assertEquals(user.getStatus(), response.getStatus());
        assertEquals(user.getCreatedAt(), response.getCreatedAt());
        assertEquals(user.getUpdatedAt(), response.getUpdatedAt());
    }

    @Test
    void testFromDomain_WithNullUser() {
        assertThrows(NullPointerException.class, () -> UserResponse.fromDomain(null));
    }

    @Test
    void testFromDomain_WithNullFields() {
        SysUser user = new SysUser();
        
        UserResponse response = UserResponse.fromDomain(user);

        assertNull(response.getId());
        assertNull(response.getUsername());
        assertNull(response.getEmail());
        assertNull(response.getRoleId());
        assertNull(response.getStatus());
        assertNull(response.getCreatedAt());
        assertNull(response.getUpdatedAt());
    }

    @Test
    void testFromDomain_WithEmptyStrings() {
        SysUser user = new SysUser();
        user.setUsername("");
        user.setEmail("");
        
        UserResponse response = UserResponse.fromDomain(user);

        assertEquals("", response.getUsername());
        assertEquals("", response.getEmail());
    }

    @Test
    void testSettersWithNullValues() {
        UserResponse response = new UserResponse();
        
        response.setId(null);
        response.setUsername(null);
        response.setEmail(null);
        response.setRoleId(null);
        response.setStatus(null);
        response.setCreatedAt(null);
        response.setUpdatedAt(null);

        assertNull(response.getId());
        assertNull(response.getUsername());
        assertNull(response.getEmail());
        assertNull(response.getRoleId());
        assertNull(response.getStatus());
        assertNull(response.getCreatedAt());
        assertNull(response.getUpdatedAt());
    }

    @Test
    void testSettersWithBoundaryValues() {
        UserResponse response = new UserResponse();
        
        response.setId(Long.MAX_VALUE);
        response.setRoleId(Long.MIN_VALUE);
        response.setStatus(Integer.MAX_VALUE);
        
        assertEquals(Long.MAX_VALUE, response.getId());
        assertEquals(Long.MIN_VALUE, response.getRoleId());
        assertEquals(Integer.MAX_VALUE, response.getStatus());
    }

    @Test
    void testSettersWithZeroValues() {
        UserResponse response = new UserResponse();
        
        response.setId(0L);
        response.setRoleId(0L);
        response.setStatus(0);
        
        assertEquals(0L, response.getId());
        assertEquals(0L, response.getRoleId());
        assertEquals(0, response.getStatus());
    }

    @Test
    void testSettersWithNegativeValues() {
        UserResponse response = new UserResponse();
        
        response.setId(-1L);
        response.setRoleId(-1L);
        response.setStatus(-1);
        
        assertEquals(-1L, response.getId());
        assertEquals(-1L, response.getRoleId());
        assertEquals(-1, response.getStatus());
    }
}
