package cn.iselab.mooctest.user.web.wrapper;

import cn.iselab.mooctest.rpc.user.data.UserDTO;
import cn.iselab.mooctest.user.model.User;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;

/**
 * @author sean
 * @date 2018-03-04.
 */
@Service
public class UserWrapper extends BaseWrapper<UserDTO, User> {

    @Override
    public UserDTO wrap(User user) {
        UserDTO userDTO = new UserDTO();

        userDTO.setAvailability(user.getAvailability());
        userDTO.setCity(user.getCity());
        userDTO.setCreateTime(user.getCreateTime().getTime());
        userDTO.setEmail(user.getEmail());
        userDTO.setId(user.getId());
        userDTO.setManualCheckValid(user.getManualCheckValid());
        userDTO.setMobile(user.getMobile());
        userDTO.setName(user.getName());
        userDTO.setPassword(user.getPassword());
        userDTO.setPhotoUrl(user.getPhotoUrl());
        userDTO.setProvince(user.getProvince());
        userDTO.setSchool(user.getSchool());
        return userDTO;
    }

    @Override
    public User unwrap(UserDTO data) {
        User user = new User();

        user.setSchool(data.getSchool());
        user.setProvince(data.getProvince());
        user.setPhotoUrl(data.getPhotoUrl());
        user.setAvailability(data.getAvailability());
        user.setCity(data.getCity());
        user.setCreateTime(new Timestamp(data.getCreateTime()));
        user.setEmail(data.getEmail());
        user.setId(data.getId());
        user.setManualCheckValid(data.getManualCheckValid());
        user.setMobile(data.getMobile());
        user.setName(data.getName());
        user.setPassword(data.getPassword());

        return user;
    }
}
