import { isNumber } from '../../../utils/utils';

export const transferAttr = (columnType, columnAttrObj) => {
    switch (String(columnType)) {
        case '9':
            let precision9;
            if (isNumber(columnAttrObj.precision)) {
                precision9 = columnAttrObj.precision;
            } else if (isNumber(columnAttrObj.decimalPartMaxLength)) {
                precision9 = columnAttrObj.decimalPartMaxLength;
            }
            columnAttrObj.precision = precision9;
            columnAttrObj.min = columnAttrObj.minValue;
            columnAttrObj.max = columnAttrObj.maxValue || 10 ** columnAttrObj.intPartMaxLength;
            break;
        case '10':
            let precision10;
            if (isNumber(columnAttrObj.decimalPartMaxLength)) {
                precision10 = columnAttrObj.decimalPartMaxLength;
            }
            const precision = Number(precision10) - 2;
            columnAttrObj.precision = precision > 0 ? precision : 0;
            columnAttrObj.min = columnAttrObj.minValue;
            columnAttrObj.max = columnAttrObj.maxValue || 10 ** columnAttrObj.intPartMaxLength;
            break;
        case '11':
            columnAttrObj.format = columnAttrObj.format.replace(/y/g, 'Y').replace(/d/g, 'D');
            columnAttrObj.showTime = /H|m|s/.test(columnAttrObj.format);
            break;
        default:
            break;
    }
    return columnAttrObj || {};
};
