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

import cn.novalon.gym.manage.sys.core.domain.SysExceptionLog;
import cn.novalon.gym.manage.db.entity.SysExceptionLogEntity;

import org.springframework.stereotype.Component;

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

/**
 * 异常日志实体转换器
 * 
 * @author 张翔
 * @date 2026-03-13
 */
@Component
public class SysExceptionLogConverter {

    public SysExceptionLog toDomain(SysExceptionLogEntity entity) {
        if (entity == null) {
            return null;
        }
        SysExceptionLog domain = new SysExceptionLog();
        domain.setId(entity.getId());
        domain.setUsername(entity.getUsername());
        domain.setTitle(entity.getTitle());
        domain.setExceptionName(entity.getExceptionName());
        domain.setMethodName(entity.getMethodName());
        domain.setMethodParams(entity.getMethodParams());
        domain.setExceptionMsg(entity.getExceptionMsg());
        domain.setExceptionStack(entity.getExceptionStack());
        domain.setIp(entity.getIp());
        domain.setCreateTime(entity.getCreateTime());
        return domain;
    }

    public SysExceptionLogEntity toEntity(SysExceptionLog domain) {
        if (domain == null) {
            return null;
        }
        SysExceptionLogEntity entity = new SysExceptionLogEntity();
        entity.setId(domain.getId());
        entity.setUsername(domain.getUsername());
        entity.setTitle(domain.getTitle());
        entity.setExceptionName(domain.getExceptionName());
        entity.setMethodName(domain.getMethodName());
        entity.setMethodParams(domain.getMethodParams());
        entity.setExceptionMsg(domain.getExceptionMsg());
        entity.setExceptionStack(domain.getExceptionStack());
        entity.setIp(domain.getIp());
        entity.setCreateTime(domain.getCreateTime());
        return entity;
    }

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

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