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

import cn.novalon.gym.manage.sys.core.domain.SysUser;
import cn.novalon.gym.manage.db.entity.SysUserEntity;

import org.springframework.stereotype.Component;

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

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

    public SysUser toDomain(SysUserEntity entity) {
        if (entity == null) {
            return null;
        }
        SysUser domain = new SysUser();
        domain.setId(entity.getId());
        domain.setUsername(entity.getUsername());
        domain.setPassword(entity.getPassword());
        domain.setEmail(entity.getEmail());
        domain.setPhone(entity.getPhone());
        domain.setNickname(entity.getNickname());
        domain.setRoleId(entity.getRoleId());
        domain.setStatus(entity.getStatus());
        domain.setCreatedAt(entity.getCreatedAt());
        domain.setUpdatedAt(entity.getUpdatedAt());
        domain.setDeletedAt(entity.getDeletedAt());
        return domain;
    }

    public SysUserEntity toEntity(SysUser domain) {
        if (domain == null) {
            return null;
        }
        SysUserEntity entity = new SysUserEntity();
        entity.setId(domain.getId());
        entity.setUsername(domain.getUsername());
        entity.setPassword(domain.getPassword());
        entity.setEmail(domain.getEmail());
        entity.setPhone(domain.getPhone());
        entity.setNickname(domain.getNickname());
        entity.setRoleId(domain.getRoleId());
        entity.setStatus(domain.getStatus());
        entity.setCreatedAt(domain.getCreatedAt());
        entity.setUpdatedAt(domain.getUpdatedAt());
        entity.setDeletedAt(domain.getDeletedAt());
        return entity;
    }

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

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