package cc.smtweb.framework.core.mvc.controller.binder.param;

import org.apache.commons.lang3.StringUtils;


public class CharEditor extends AbstractParameterEditor {
    private static final char CHAR_ZERO = '\u0000';
    private final boolean automicType;

    public CharEditor(int header, boolean automicType) {
        super(header);
        this.automicType = automicType;
    }

    @Override
    protected Object parseText(Object value) {
        if (value == null) {
            return automicType ? CHAR_ZERO: null;
        }

        String text = value.toString();

        if (StringUtils.isBlank(text)) {
            return automicType ? CHAR_ZERO: null;
        }

        return text.charAt(0);
    }
}
