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

import cn.novalon.gym.manage.file.core.domain.SysFile;
import cn.novalon.gym.manage.db.entity.SysFileEntity;

import org.springframework.stereotype.Component;

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

/**
 * 文件实体转换器
 * 
 * @author 张翔
 * @date 2026-03-13
 */
@Component
public class SysFileConverter {

    public SysFile toDomain(SysFileEntity entity) {
        if (entity == null) {
            return null;
        }
        SysFile domain = new SysFile();
        domain.setId(entity.getId());
        domain.setFileName(entity.getFileName());
        domain.setFilePath(entity.getFilePath());
        domain.setFileSize(entity.getFileSize());
        domain.setFileType(entity.getFileType());
        domain.setStorageType(entity.getStorageType());
        domain.setCreateBy(entity.getCreateBy());
        domain.setCreatedAt(entity.getCreatedAt());
        return domain;
    }

    public SysFileEntity toEntity(SysFile domain) {
        if (domain == null) {
            return null;
        }
        SysFileEntity entity = new SysFileEntity();
        entity.setId(domain.getId());
        entity.setFileName(domain.getFileName());
        entity.setFilePath(domain.getFilePath());
        entity.setFileSize(domain.getFileSize());
        entity.setFileType(domain.getFileType());
        entity.setStorageType(domain.getStorageType());
        entity.setCreateBy(domain.getCreateBy());
        entity.setCreatedAt(domain.getCreatedAt());
        return entity;
    }

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

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