import dayjs from 'dayjs';
import _ from 'lodash';

export default {
    filesFormatter(arr) {
        if (!arr || !arr.length) return [];
        return arr.map((item) => item);
    },
    imageFormatter(arr) {
        if (!arr || !arr.length) return []
        return arr.map(item => ({
            publicUrl: item.publicUrl || ''
        }))
    },
    oneImageFormatter(arr) {
        if (!arr || !arr.length) return ''
        return arr[0].publicUrl || ''
    },
    dateFormatter(date) {
        if (!date) return ''
        return dayjs(date).format('YYYY-MM-DD')
    },
    dateTimeFormatter(date) {
        if (!date) return ''
        return dayjs(date).format('YYYY-MM-DD HH:mm')
    },
    booleanFormatter(val) {
        return val ? 'Yes' : 'No'
    },
    dataGridEditFormatter(obj) {
        return _.transform(obj, (result, value, key) => {
            if (_.isArray(value)) {
                result[key] = _.map(value, 'id');
            } else if (_.isObject(value)) {
                result[key] = value.id;
            } else {
                result[key] = value;
            }
        });
    },
    
        
        usersManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.firstName)
        },
        usersOneListFormatter(val) {
            if (!val) return ''
            return val.firstName
        },
        usersManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.firstName}
            });
        },
        usersOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.firstName, id: val.id}
        },
        
    
        
        rolesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        rolesOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        rolesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        rolesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        permissionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        permissionsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        permissionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        permissionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
    
        
    
        
        trading_accountsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        trading_accountsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        trading_accountsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        trading_accountsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        instrumentsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.symbol)
        },
        instrumentsOneListFormatter(val) {
            if (!val) return ''
            return val.symbol
        },
        instrumentsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.symbol}
            });
        },
        instrumentsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.symbol, id: val.id}
        },
        
    
        
        setupsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        setupsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        setupsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        setupsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        tagsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        tagsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        tagsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        tagsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        tradesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.notes)
        },
        tradesOneListFormatter(val) {
            if (!val) return ''
            return val.notes
        },
        tradesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.notes}
            });
        },
        tradesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.notes, id: val.id}
        },
        
    
        
    
        
        trade_rulesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        trade_rulesOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        trade_rulesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        trade_rulesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
    
        
    
        
        goalsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.title)
        },
        goalsOneListFormatter(val) {
            if (!val) return ''
            return val.title
        },
        goalsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.title}
            });
        },
        goalsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.title, id: val.id}
        },
        
    
        
    
        
    
        
    
        
        csv_import_jobsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.original_filename)
        },
        csv_import_jobsOneListFormatter(val) {
            if (!val) return ''
            return val.original_filename
        },
        csv_import_jobsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.original_filename}
            });
        },
        csv_import_jobsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.original_filename, id: val.id}
        },
        
    
        
    
        
        broker_connectionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.connection_label)
        },
        broker_connectionsOneListFormatter(val) {
            if (!val) return ''
            return val.connection_label
        },
        broker_connectionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.connection_label}
            });
        },
        broker_connectionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.connection_label, id: val.id}
        },
        
    
        
    
        
        ai_insight_runsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.output_summary)
        },
        ai_insight_runsOneListFormatter(val) {
            if (!val) return ''
            return val.output_summary
        },
        ai_insight_runsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.output_summary}
            });
        },
        ai_insight_runsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.output_summary, id: val.id}
        },
        
    
        
    
        
        alert_rulesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.notes)
        },
        alert_rulesOneListFormatter(val) {
            if (!val) return ''
            return val.notes
        },
        alert_rulesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.notes}
            });
        },
        alert_rulesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.notes, id: val.id}
        },
        
    
        
    
        
    
        
    
}
