package cn.novalon.manage.db.converter;

import cn.novalon.manage.sys.core.domain.SysRole;
import cn.novalon.manage.db.entity.SysRoleEntity;

import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 角色实体转换器
 * 
 * @author 张翔
 * @date 2026-03-13
 */
@Component
public class SysRoleConverter {

    public SysRole toDomain(SysRoleEntity entity) {
        if (entity == null) {
            return null;
        }
        SysRole domain = new SysRole();
        domain.setId(entity.getId());
        domain.setRoleName(entity.getRoleName());
        domain.setRoleKey(entity.getRoleKey());
        domain.setRoleSort(entity.getRoleSort());
        domain.setStatus(entity.getStatus());
        domain.setCreatedAt(entity.getCreatedAt());
        domain.setUpdatedAt(entity.getUpdatedAt());
        domain.setDeletedAt(entity.getDeletedAt());
        return domain;
    }

    public SysRoleEntity toEntity(SysRole domain) {
        if (domain == null) {
            return null;
        }
        SysRoleEntity entity = new SysRoleEntity();
        entity.setId(domain.getId());
        entity.setRoleName(domain.getRoleName());
        entity.setRoleKey(domain.getRoleKey());
        entity.setRoleSort(domain.getRoleSort());
        entity.setStatus(domain.getStatus());
        entity.setCreatedAt(domain.getCreatedAt());
        entity.setUpdatedAt(domain.getUpdatedAt());
        entity.setDeletedAt(domain.getDeletedAt());
        return entity;
    }

    public List<SysRole> toDomainList(List<SysRoleEntity> entities) {
        if (entities == null) {
            return null;
        }
        return entities.stream()
                .map(this::toDomain)
                .collect(Collectors.toList());
    }

    public List<SysRoleEntity> toEntityList(List<SysRole> domains) {
        if (domains == null) {
            return null;
        }
        return domains.stream()
                .map(this::toEntity)
                .collect(Collectors.toList());
    }
}
