package cn.novalon.manage.db.converter;

import cn.novalon.manage.db.entity.UserRoleEntity;
import cn.novalon.manage.sys.core.domain.UserRole;
import org.springframework.stereotype.Component;

@Component
public class UserRoleConverter {

    public UserRole toDomain(UserRoleEntity entity) {
        if (entity == null) {
            return null;
        }
        
        UserRole domain = new UserRole();
        domain.setId(entity.getId());
        domain.setUserId(entity.getUserId());
        domain.setRoleId(entity.getRoleId());
        domain.setCreatedAt(entity.getCreatedAt());
        domain.setCreatedBy(entity.getCreatedBy());
        return domain;
    }

    public UserRoleEntity toEntity(UserRole domain) {
        if (domain == null) {
            return null;
        }
        
        UserRoleEntity entity = new UserRoleEntity();
        entity.setId(domain.getId());
        entity.setUserId(domain.getUserId());
        entity.setRoleId(domain.getRoleId());
        entity.setCreatedAt(domain.getCreatedAt());
        entity.setCreatedBy(domain.getCreatedBy());
        return entity;
    }
}
