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

import cn.novalon.gym.manage.sys.core.domain.SysMenu;
import cn.novalon.gym.manage.db.entity.SysMenuEntity;

import org.springframework.stereotype.Component;

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

/**
 * 菜单实体转换器
 * 
 * @author 张翔
 * @date 2026-03-13
 */
@Component
public class SysMenuConverter {

    public SysMenu toDomain(SysMenuEntity entity) {
        if (entity == null) {
            return null;
        }
        SysMenu domain = new SysMenu();
        domain.setId(entity.getId());
        domain.setMenuName(entity.getMenuName());
        domain.setParentId(entity.getParentId());
        domain.setOrderNum(entity.getOrderNum());
        domain.setMenuType(entity.getMenuType());
        domain.setPerms(entity.getPerms());
        domain.setComponent(entity.getComponent());
        domain.setStatus(entity.getStatus());
        domain.setCreateBy(entity.getCreateBy());
        domain.setUpdateBy(entity.getUpdateBy());
        domain.setCreatedAt(entity.getCreatedAt());
        domain.setUpdatedAt(entity.getUpdatedAt());
        domain.setDeletedAt(entity.getDeletedAt());
        return domain;
    }

    public SysMenuEntity toEntity(SysMenu domain) {
        if (domain == null) {
            return null;
        }
        SysMenuEntity entity = new SysMenuEntity();
        entity.setId(domain.getId());
        entity.setMenuName(domain.getMenuName());
        entity.setParentId(domain.getParentId());
        entity.setOrderNum(domain.getOrderNum());
        entity.setMenuType(domain.getMenuType());
        entity.setPerms(domain.getPerms());
        entity.setComponent(domain.getComponent());
        entity.setStatus(domain.getStatus());
        entity.setCreateBy(domain.getCreateBy());
        entity.setUpdateBy(domain.getUpdateBy());
        entity.setCreatedAt(domain.getCreatedAt());
        entity.setUpdatedAt(domain.getUpdatedAt());
        entity.setDeletedAt(domain.getDeletedAt());
        return entity;
    }

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

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