package com.red.circle.other.infra.convertor;

import com.red.circle.other.domain.redpacket.UserRedPacket;
import com.red.circle.other.infra.database.rds.entity.UserRedPacketEntity;

/**
 * 用户红包转换器
 */
public class UserRedPacketConvertor {

    public static UserRedPacket toDomain(UserRedPacketEntity entity) {
        if (entity == null) {
            return null;
        }
        return UserRedPacket.builder()
                .id(entity.getId())
                .packetId(entity.getPacketId())
                .senderUserId(entity.getSenderUserId())
                .receiverUserId(entity.getReceiverUserId())
                .packetType(entity.getPacketType())
                .totalAmount(entity.getTotalAmount())
                .handlingFee(entity.getHandlingFee())
                .expireTime(entity.getExpireTime())
                .status(entity.getStatus())
                .refundStatus(entity.getRefundStatus())
                .grabbedAt(entity.getGrabbedAt())
                .createTime(entity.getCreateTime())
                .updateTime(entity.getUpdateTime())
                .build();
    }

    public static UserRedPacketEntity toEntity(UserRedPacket domain) {
        if (domain == null) {
            return null;
        }
        UserRedPacketEntity entity = new UserRedPacketEntity();
        entity.setId(domain.getId());
        entity.setPacketId(domain.getPacketId());
        entity.setSenderUserId(domain.getSenderUserId());
        entity.setReceiverUserId(domain.getReceiverUserId());
        entity.setPacketType(domain.getPacketType());
        entity.setTotalAmount(domain.getTotalAmount());
        entity.setHandlingFee(domain.getHandlingFee());
        entity.setExpireTime(domain.getExpireTime());
        entity.setStatus(domain.getStatus());
        entity.setRefundStatus(domain.getRefundStatus());
        entity.setGrabbedAt(domain.getGrabbedAt());
        entity.setCreateTime(domain.getCreateTime());
        entity.setUpdateTime(domain.getUpdateTime());
        return entity;
    }
}
