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

import com.red.circle.other.domain.admintask.AdminTaskRecord;
import com.red.circle.other.domain.admintask.AdminTaskStatus;
import com.red.circle.other.domain.admintask.AdminTaskType;
import com.red.circle.other.app.dto.clientobject.AdminTaskRecordCO;
import org.springframework.stereotype.Component;

/**
 * 管理员任务转换器
 *
 * @author tf
 * @date 2025-11-25
 */
@Component
public class AdminTaskConvertor {

    public AdminTaskRecordCO toRecordCO(AdminTaskRecord record) {
        if (record == null) {
            return null;
        }

        AdminTaskRecordCO co = new AdminTaskRecordCO();
        co.setTaskType(record.getTaskType());
        co.setTargetCount(record.getTargetCount());
        co.setCompletedCount(record.getCompletedCount());
        co.setStatus(record.getStatus());
        co.setCompletionRate(record.getCompletionRate());

        // 设置任务名称和单位
        AdminTaskType taskType = AdminTaskType.fromCode(record.getTaskType());
        if (taskType != null) {
            co.setTaskName(taskType.getName());
            co.setUnit(taskType.getUnit());
        }

        // 设置状态名称
        AdminTaskStatus status = AdminTaskStatus.fromCode(record.getStatus());
        if (status != null) {
            co.setStatusName(status.getName());
        }

        return co;
    }
}
