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

import cn.novalon.gym.manage.sys.core.domain.SysRolePermission;
import cn.novalon.gym.manage.db.entity.SysRolePermissionEntity;

import org.springframework.stereotype.Component;

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

/**
 * 角色权限关联实体转换器
 * 
 * @author 张翔
 * @date 2026-03-25
 */
@Component
public class SysRolePermissionConverter {

    public SysRolePermission toDomain(SysRolePermissionEntity entity) {
        if (entity == null) {
            return null;
        }
        SysRolePermission domain = new SysRolePermission();
        domain.setId(entity.getId());
        domain.setRoleId(entity.getRoleId());
        domain.setPermissionId(entity.getPermissionId());
        domain.setCreatedAt(entity.getCreatedAt());
        domain.setUpdatedAt(entity.getUpdatedAt());
        return domain;
    }

    public SysRolePermissionEntity toEntity(SysRolePermission domain) {
        if (domain == null) {
            return null;
        }
        SysRolePermissionEntity entity = new SysRolePermissionEntity();
        entity.setId(domain.getId());
        entity.setRoleId(domain.getRoleId());
        entity.setPermissionId(domain.getPermissionId());
        entity.setCreatedAt(domain.getCreatedAt());
        entity.setUpdatedAt(domain.getUpdatedAt());
        return entity;
    }

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

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