package com.base.task.core;

import com.base.task.model.input.Input;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.lang.reflect.Field;

@Slf4j
public class taskUtils {
    public static String getTaskInputString(Class<? extends Input> inputClazz, Input input) {
        StringBuilder inputBuilder = new StringBuilder();
        try {
            Field[] fields = inputClazz.getDeclaredFields();
            for (Field field : fields) {
                field.setAccessible(true);
                String value = (String) field.get(input);
                if (!StringUtils.isNotEmpty(value)){
                    continue;
                }
                if (value.equals("lineBreak")) {
                    inputBuilder.append("\n");
                } else {
                    inputBuilder.append(value).append(" ");
                }
            }
        } catch (Exception e) {
            log.info(e.getMessage(), e);
        }
        return inputBuilder.toString();
    }
}
