package cn.novalon.manage.db.converter;

import cn.novalon.manage.sys.core.domain.SysDictData;
import cn.novalon.manage.db.entity.SysDictDataEntity;
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 SysDictDataConverterTest {

    private SysDictDataConverter converter;
    private SysDictDataEntity testEntity;
    private SysDictData testDomain;

    @BeforeEach
    void setUp() {
        converter = new SysDictDataConverter();
        
        testEntity = new SysDictDataEntity();
        testEntity.setId(1L);
        testEntity.setDictSort(1);
        testEntity.setDictLabel("正常");
        testEntity.setDictValue("0");
        testEntity.setDictType("user_status");
        testEntity.setCssClass("default");
        testEntity.setListClass("default");
        testEntity.setIsDefault("Y");
        testEntity.setStatus("0");
        testEntity.setCreatedAt(LocalDateTime.now());
        testEntity.setUpdatedAt(LocalDateTime.now());
        
        testDomain = new SysDictData();
        testDomain.setId(1L);
        testDomain.setDictSort(1);
        testDomain.setDictLabel("正常");
        testDomain.setDictValue("0");
        testDomain.setDictType("user_status");
        testDomain.setCssClass("default");
        testDomain.setListClass("default");
        testDomain.setIsDefault("Y");
        testDomain.setStatus("0");
        testDomain.setCreatedAt(LocalDateTime.now());
        testDomain.setUpdatedAt(LocalDateTime.now());
    }

    @Test
    void testToDomain() {
        SysDictData result = converter.toDomain(testEntity);
        
        assertThat(result).isNotNull();
        assertThat(result.getId()).isEqualTo(testEntity.getId());
        assertThat(result.getDictSort()).isEqualTo(testEntity.getDictSort());
        assertThat(result.getDictLabel()).isEqualTo(testEntity.getDictLabel());
        assertThat(result.getDictValue()).isEqualTo(testEntity.getDictValue());
        assertThat(result.getDictType()).isEqualTo(testEntity.getDictType());
        assertThat(result.getCssClass()).isEqualTo(testEntity.getCssClass());
        assertThat(result.getListClass()).isEqualTo(testEntity.getListClass());
        assertThat(result.getIsDefault()).isEqualTo(testEntity.getIsDefault());
        assertThat(result.getStatus()).isEqualTo(testEntity.getStatus());
    }

    @Test
    void testToEntity() {
        SysDictDataEntity result = converter.toEntity(testDomain);
        
        assertThat(result).isNotNull();
        assertThat(result.getId()).isEqualTo(testDomain.getId());
        assertThat(result.getDictSort()).isEqualTo(testDomain.getDictSort());
        assertThat(result.getDictLabel()).isEqualTo(testDomain.getDictLabel());
        assertThat(result.getDictValue()).isEqualTo(testDomain.getDictValue());
        assertThat(result.getDictType()).isEqualTo(testDomain.getDictType());
        assertThat(result.getCssClass()).isEqualTo(testDomain.getCssClass());
        assertThat(result.getListClass()).isEqualTo(testDomain.getListClass());
        assertThat(result.getIsDefault()).isEqualTo(testDomain.getIsDefault());
        assertThat(result.getStatus()).isEqualTo(testDomain.getStatus());
    }

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

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