package cn.novalon.gym.manage.db.converter;

import cn.novalon.gym.manage.sys.core.domain.SysRole;
import cn.novalon.gym.manage.db.entity.SysRoleEntity;
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 SysRoleConverterTest {

    private SysRoleConverter converter;
    private SysRoleEntity testEntity;
    private SysRole testDomain;

    @BeforeEach
    void setUp() {
        converter = new SysRoleConverter();
        
        testEntity = new SysRoleEntity();
        testEntity.setId(1L);
        testEntity.setRoleName("ADMIN");
        testEntity.setRoleKey("admin");
        testEntity.setRoleSort(1);
        testEntity.setStatus(1);
        testEntity.setCreatedAt(LocalDateTime.now());
        testEntity.setUpdatedAt(LocalDateTime.now());
        
        testDomain = new SysRole();
        testDomain.setId(1L);
        testDomain.setRoleName("ADMIN");
        testDomain.setRoleKey("admin");
        testDomain.setRoleSort(1);
        testDomain.setStatus(1);
        testDomain.setCreatedAt(LocalDateTime.now());
        testDomain.setUpdatedAt(LocalDateTime.now());
    }

    @Test
    void testToDomain() {
        SysRole result = converter.toDomain(testEntity);
        
        assertThat(result).isNotNull();
        assertThat(result.getId()).isEqualTo(testEntity.getId());
        assertThat(result.getRoleName()).isEqualTo(testEntity.getRoleName());
        assertThat(result.getRoleKey()).isEqualTo(testEntity.getRoleKey());
        assertThat(result.getRoleSort()).isEqualTo(testEntity.getRoleSort());
        assertThat(result.getStatus()).isEqualTo(testEntity.getStatus());
    }

    @Test
    void testToEntity() {
        SysRoleEntity result = converter.toEntity(testDomain);
        
        assertThat(result).isNotNull();
        assertThat(result.getId()).isEqualTo(testDomain.getId());
        assertThat(result.getRoleName()).isEqualTo(testDomain.getRoleName());
        assertThat(result.getRoleKey()).isEqualTo(testDomain.getRoleKey());
        assertThat(result.getRoleSort()).isEqualTo(testDomain.getRoleSort());
        assertThat(result.getStatus()).isEqualTo(testDomain.getStatus());
    }

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

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