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

import cn.novalon.gym.manage.auth.domain.User;
import cn.novalon.gym.manage.auth.dto.UserInfo;
import cn.novalon.gym.manage.auth.entity.UserEntity;

public class UserConverter {

    public static User toDomain(UserEntity entity) {
        if (entity == null) {
            return null;
        }
        User user = new User();
        user.setId(entity.getId());
        user.setUsername(entity.getUsername());
        user.setEmail(entity.getEmail());
        user.setPhone(entity.getPhone());
        user.setNickname(entity.getNickname());
        user.setStatus(entity.getStatus());
        user.setRoleId(entity.getRoleId());
        user.setCreateBy(entity.getCreateBy());
        user.setUpdateBy(entity.getUpdateBy());
        user.setCreatedAt(entity.getCreatedAt());
        user.setUpdatedAt(entity.getUpdatedAt());
        user.setDeletedAt(entity.getDeletedAt());
        return user;
    }

    public static UserEntity toEntity(User domain) {
        if (domain == null) {
            return null;
        }
        UserEntity entity = new UserEntity();
        entity.setId(domain.getId());
        entity.setUsername(domain.getUsername());
        entity.setEmail(domain.getEmail());
        entity.setPhone(domain.getPhone());
        entity.setNickname(domain.getNickname());
        entity.setStatus(domain.getStatus());
        entity.setRoleId(domain.getRoleId());
        entity.setCreateBy(domain.getCreateBy());
        entity.setUpdateBy(domain.getUpdateBy());
        entity.setCreatedAt(domain.getCreatedAt());
        entity.setUpdatedAt(domain.getUpdatedAt());
        entity.setDeletedAt(domain.getDeletedAt());
        return entity;
    }

    public static UserInfo toUserInfo(User user) {
        if (user == null) {
            return null;
        }
        UserInfo userInfo = new UserInfo();
        userInfo.setId(user.getId());
        userInfo.setUsername(user.getUsername());
        userInfo.setEmail(user.getEmail());
        userInfo.setPhone(user.getPhone());
        userInfo.setNickname(user.getNickname());
        userInfo.setStatus(user.getStatus());
        userInfo.setRoleId(user.getRoleId());
        return userInfo;
    }
}