package cn.novalon.manage.db.converter;

import cn.novalon.manage.notify.core.domain.SysNotice;
import cn.novalon.manage.db.entity.SysNoticeEntity;

import org.springframework.stereotype.Component;

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

/**
 * 通知公告实体转换器
 * 
 * @author 张翔
 * @date 2026-03-13
 */
@Component
public class SysNoticeConverter {

    public SysNotice toDomain(SysNoticeEntity entity) {
        if (entity == null) {
            return null;
        }
        SysNotice domain = new SysNotice();
        domain.setId(entity.getId());
        domain.setNoticeTitle(entity.getNoticeTitle());
        domain.setNoticeType(entity.getNoticeType());
        domain.setNoticeContent(entity.getNoticeContent());
        domain.setStatus(entity.getStatus());
        domain.setCreatedAt(entity.getCreatedAt());
        domain.setUpdatedAt(entity.getUpdatedAt());
        domain.setDeletedAt(entity.getDeletedAt());
        return domain;
    }

    public SysNoticeEntity toEntity(SysNotice domain) {
        if (domain == null) {
            return null;
        }
        SysNoticeEntity entity = new SysNoticeEntity();
        entity.setId(domain.getId());
        entity.setNoticeTitle(domain.getNoticeTitle());
        entity.setNoticeType(domain.getNoticeType());
        entity.setNoticeContent(domain.getNoticeContent());
        entity.setStatus(domain.getStatus());
        entity.setCreatedAt(domain.getCreatedAt());
        entity.setUpdatedAt(domain.getUpdatedAt());
        entity.setDeletedAt(domain.getDeletedAt());
        return entity;
    }

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

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