package cn.novalon.manage.db.converter;

import cn.novalon.manage.notify.core.domain.SysUserMessage;
import cn.novalon.manage.db.entity.SysUserMessageEntity;

import org.springframework.stereotype.Component;

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

/**
 * 用户消息实体转换器
 * 
 * @author 张翔
 * @date 2026-03-13
 */
@Component
public class SysUserMessageConverter {

    public SysUserMessage toDomain(SysUserMessageEntity entity) {
        if (entity == null) {
            return null;
        }
        SysUserMessage domain = new SysUserMessage();
        domain.setId(entity.getId());
        domain.setUserId(entity.getUserId());
        domain.setTitle(entity.getTitle());
        domain.setContent(entity.getContent());
        domain.setMessageType(entity.getMessageType());
        domain.setIsRead(entity.getIsRead());
        domain.setCreateTime(entity.getCreateTime());
        return domain;
    }

    public SysUserMessageEntity toEntity(SysUserMessage domain) {
        if (domain == null) {
            return null;
        }
        SysUserMessageEntity entity = new SysUserMessageEntity();
        entity.setId(domain.getId());
        entity.setUserId(domain.getUserId());
        entity.setTitle(domain.getTitle());
        entity.setContent(domain.getContent());
        entity.setMessageType(domain.getMessageType());
        entity.setIsRead(domain.getIsRead());
        entity.setCreateTime(domain.getCreateTime());
        return entity;
    }

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

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