package cn.novalon.manage.db.converter;

import cn.novalon.manage.sys.core.domain.Dictionary;
import cn.novalon.manage.db.entity.DictionaryEntity;
import org.springframework.stereotype.Component;

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

/**
 * 字典实体转换器
 * 
 * @author 张翔
 * @date 2026-03-13
 */
@Component
public class DictionaryConverter {

    public DictionaryEntity toEntity(Dictionary domain) {
        if (domain == null) {
            return null;
        }
        DictionaryEntity entity = new DictionaryEntity();
        entity.setId(domain.getId());
        entity.setType(domain.getType());
        entity.setCode(domain.getCode());
        entity.setName(domain.getName());
        entity.setValue(domain.getValue());
        entity.setRemark(domain.getRemark());
        entity.setSort(domain.getSort());
        entity.setCreateBy(domain.getCreateBy());
        entity.setCreatedAt(domain.getCreatedAt());
        entity.setUpdatedAt(domain.getUpdatedAt());
        return entity;
    }

    public Dictionary toDomain(DictionaryEntity entity) {
        if (entity == null) {
            return null;
        }
        Dictionary domain = new Dictionary();
        domain.setId(entity.getId());
        domain.setType(entity.getType());
        domain.setCode(entity.getCode());
        domain.setName(entity.getName());
        domain.setValue(entity.getValue());
        domain.setRemark(entity.getRemark());
        domain.setSort(entity.getSort());
        domain.setCreateBy(entity.getCreateBy());
        domain.setCreatedAt(entity.getCreatedAt());
        domain.setUpdatedAt(entity.getUpdatedAt());
        return domain;
    }

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

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