package cn.novalon.manage.db.converter;

import cn.novalon.manage.sys.core.domain.SysMenu;
import cn.novalon.manage.db.entity.SysMenuEntity;
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 SysMenuConverterTest {

    private SysMenuConverter converter;
    private SysMenuEntity testEntity;
    private SysMenu testDomain;

    @BeforeEach
    void setUp() {
        converter = new SysMenuConverter();
        
        testEntity = new SysMenuEntity();
        testEntity.setId(1L);
        testEntity.setMenuName("用户管理");
        testEntity.setParentId(0L);
        testEntity.setOrderNum(1);
        testEntity.setMenuType("M");
        testEntity.setPerms("user:list");
        testEntity.setComponent("user/index");
        testEntity.setStatus(1);
        testEntity.setCreateBy("admin");
        testEntity.setUpdateBy("admin");
        testEntity.setCreatedAt(LocalDateTime.now());
        testEntity.setUpdatedAt(LocalDateTime.now());
        
        testDomain = new SysMenu();
        testDomain.setId(1L);
        testDomain.setMenuName("用户管理");
        testDomain.setParentId(0L);
        testDomain.setOrderNum(1);
        testDomain.setMenuType("M");
        testDomain.setPerms("user:list");
        testDomain.setComponent("user/index");
        testDomain.setStatus(1);
        testDomain.setCreateBy("admin");
        testDomain.setUpdateBy("admin");
        testDomain.setCreatedAt(LocalDateTime.now());
        testDomain.setUpdatedAt(LocalDateTime.now());
    }

    @Test
    void testToDomain() {
        SysMenu result = converter.toDomain(testEntity);
        
        assertThat(result).isNotNull();
        assertThat(result.getId()).isEqualTo(testEntity.getId());
        assertThat(result.getMenuName()).isEqualTo(testEntity.getMenuName());
        assertThat(result.getParentId()).isEqualTo(testEntity.getParentId());
        assertThat(result.getOrderNum()).isEqualTo(testEntity.getOrderNum());
        assertThat(result.getMenuType()).isEqualTo(testEntity.getMenuType());
        assertThat(result.getPerms()).isEqualTo(testEntity.getPerms());
        assertThat(result.getComponent()).isEqualTo(testEntity.getComponent());
        assertThat(result.getStatus()).isEqualTo(testEntity.getStatus());
        assertThat(result.getCreateBy()).isEqualTo(testEntity.getCreateBy());
        assertThat(result.getUpdateBy()).isEqualTo(testEntity.getUpdateBy());
    }

    @Test
    void testToEntity() {
        SysMenuEntity result = converter.toEntity(testDomain);
        
        assertThat(result).isNotNull();
        assertThat(result.getId()).isEqualTo(testDomain.getId());
        assertThat(result.getMenuName()).isEqualTo(testDomain.getMenuName());
        assertThat(result.getParentId()).isEqualTo(testDomain.getParentId());
        assertThat(result.getOrderNum()).isEqualTo(testDomain.getOrderNum());
        assertThat(result.getMenuType()).isEqualTo(testDomain.getMenuType());
        assertThat(result.getPerms()).isEqualTo(testDomain.getPerms());
        assertThat(result.getComponent()).isEqualTo(testDomain.getComponent());
        assertThat(result.getStatus()).isEqualTo(testDomain.getStatus());
        assertThat(result.getCreateBy()).isEqualTo(testDomain.getCreateBy());
        assertThat(result.getUpdateBy()).isEqualTo(testDomain.getUpdateBy());
    }

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

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