package com.red.circle.other.app.convertor.user;

import com.red.circle.other.app.dto.clientobject.activity.RankingActivityRecordCO;
import com.red.circle.other.infra.database.mongo.entity.activity.RankingActivityRecord;
import com.red.circle.tool.core.num.NumUtils;
import org.springframework.stereotype.Component;

/**
 * 排行榜活动转换器
 */
@Component
public class RankingActivityConvertor {

    /**
     * 实体转换为 CO
     */
    public RankingActivityRecordCO toRecordCO(RankingActivityRecord record) {
        if (record == null) {
            return null;
        }

        RankingActivityRecordCO co = new RankingActivityRecordCO();
        co.setUserId(record.getUserId());
        co.setUserSex(record.getUserSex());
        co.setQuantity(NumUtils.formatLong(record.getQuantity()));
        co.setExtData(record.getExtData());

        // 设置活动类型信息
        if (record.getActivityType() != null) {
            co.setActivityType(record.getActivityType().getCode());
            co.setActivityTypeName(record.getActivityType().getName());
        }

        // 设置周期类型信息
        if (record.getCycleType() != null) {
            co.setCycleType(record.getCycleType().getCode());
            co.setCycleTypeName(record.getCycleType().getName());
        }

        co.setCycleKey(record.getCycleKey());

        // 设置统计维度信息
        if (record.getDimension() != null) {
            co.setDimension(record.getDimension().getCode());
            co.setDimensionName(record.getDimension().getName());
            co.setDimensionUnit(record.getDimension().getUnit());
        }

        return co;
    }
}