package cn.novalon.manage.db.converter;

import cn.novalon.manage.sys.core.domain.SysLoginLog;
import cn.novalon.manage.db.entity.SysLoginLogEntity;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;

import java.time.LocalDateTime;

import static org.assertj.core.api.Assertions.assertThat;

@ExtendWith(MockitoExtension.class)
class SysLoginLogConverterTest {

    private SysLoginLogConverter converter;
    private SysLoginLogEntity testEntity;
    private SysLoginLog testDomain;

    @BeforeEach
    void setUp() {
        converter = new SysLoginLogConverter();
        
        testEntity = new SysLoginLogEntity();
        testEntity.setId(1L);
        testEntity.setUsername("admin");
        testEntity.setIp("127.0.0.1");
        testEntity.setLocation("北京");
        testEntity.setBrowser("Chrome");
        testEntity.setOs("Windows 10");
        testEntity.setStatus("0");
        testEntity.setMessage("登录成功");
        testEntity.setLoginTime(LocalDateTime.now());
        
        testDomain = new SysLoginLog();
        testDomain.setId(1L);
        testDomain.setUsername("admin");
        testDomain.setIp("127.0.0.1");
        testDomain.setLocation("北京");
        testDomain.setBrowser("Chrome");
        testDomain.setOs("Windows 10");
        testDomain.setStatus("0");
        testDomain.setMessage("登录成功");
        testDomain.setLoginTime(LocalDateTime.now());
    }

    @Test
    void testToDomain() {
        SysLoginLog result = converter.toDomain(testEntity);
        
        assertThat(result).isNotNull();
        assertThat(result.getId()).isEqualTo(testEntity.getId());
        assertThat(result.getUsername()).isEqualTo(testEntity.getUsername());
        assertThat(result.getIp()).isEqualTo(testEntity.getIp());
        assertThat(result.getLocation()).isEqualTo(testEntity.getLocation());
        assertThat(result.getBrowser()).isEqualTo(testEntity.getBrowser());
        assertThat(result.getOs()).isEqualTo(testEntity.getOs());
        assertThat(result.getStatus()).isEqualTo(testEntity.getStatus());
        assertThat(result.getMessage()).isEqualTo(testEntity.getMessage());
        assertThat(result.getLoginTime()).isEqualTo(testEntity.getLoginTime());
    }

    @Test
    void testToEntity() {
        SysLoginLogEntity result = converter.toEntity(testDomain);
        
        assertThat(result).isNotNull();
        assertThat(result.getId()).isEqualTo(testDomain.getId());
        assertThat(result.getUsername()).isEqualTo(testDomain.getUsername());
        assertThat(result.getIp()).isEqualTo(testDomain.getIp());
        assertThat(result.getLocation()).isEqualTo(testDomain.getLocation());
        assertThat(result.getBrowser()).isEqualTo(testDomain.getBrowser());
        assertThat(result.getOs()).isEqualTo(testDomain.getOs());
        assertThat(result.getStatus()).isEqualTo(testDomain.getStatus());
        assertThat(result.getMessage()).isEqualTo(testDomain.getMessage());
        assertThat(result.getLoginTime()).isEqualTo(testDomain.getLoginTime());
    }

    @Test
    void testToDomainWithNull() {
        SysLoginLog result = converter.toDomain(null);
        assertThat(result).isNull();
    }

    @Test
    void testToEntityWithNull() {
        SysLoginLogEntity result = converter.toEntity(null);
        assertThat(result).isNull();
    }
}