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}
        },
        
    
        
        brandsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.brand_name)
        },
        brandsOneListFormatter(val) {
            if (!val) return ''
            return val.brand_name
        },
        brandsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.brand_name}
            });
        },
        brandsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.brand_name, id: val.id}
        },
        
    
        
        brand_voice_profilesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.profile_name)
        },
        brand_voice_profilesOneListFormatter(val) {
            if (!val) return ''
            return val.profile_name
        },
        brand_voice_profilesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.profile_name}
            });
        },
        brand_voice_profilesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.profile_name, id: val.id}
        },
        
    
        
        brain_profilesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.profile_name)
        },
        brain_profilesOneListFormatter(val) {
            if (!val) return ''
            return val.profile_name
        },
        brain_profilesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.profile_name}
            });
        },
        brain_profilesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.profile_name, id: val.id}
        },
        
    
        
        skill_modulesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.module_name)
        },
        skill_modulesOneListFormatter(val) {
            if (!val) return ''
            return val.module_name
        },
        skill_modulesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.module_name}
            });
        },
        skill_modulesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.module_name, id: val.id}
        },
        
    
        
    
        
        knowledge_sourcesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.source_name)
        },
        knowledge_sourcesOneListFormatter(val) {
            if (!val) return ''
            return val.source_name
        },
        knowledge_sourcesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.source_name}
            });
        },
        knowledge_sourcesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.source_name, id: val.id}
        },
        
    
        
        knowledge_documentsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.document_title)
        },
        knowledge_documentsOneListFormatter(val) {
            if (!val) return ''
            return val.document_title
        },
        knowledge_documentsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.document_title}
            });
        },
        knowledge_documentsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.document_title, id: val.id}
        },
        
    
        
        knowledge_chunksManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.chunk_label)
        },
        knowledge_chunksOneListFormatter(val) {
            if (!val) return ''
            return val.chunk_label
        },
        knowledge_chunksManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.chunk_label}
            });
        },
        knowledge_chunksOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.chunk_label, id: val.id}
        },
        
    
        
    
        
        campaignsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.campaign_name)
        },
        campaignsOneListFormatter(val) {
            if (!val) return ''
            return val.campaign_name
        },
        campaignsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.campaign_name}
            });
        },
        campaignsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.campaign_name, id: val.id}
        },
        
    
        
        campaign_brain_configsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.layer_name)
        },
        campaign_brain_configsOneListFormatter(val) {
            if (!val) return ''
            return val.layer_name
        },
        campaign_brain_configsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.layer_name}
            });
        },
        campaign_brain_configsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.layer_name, id: val.id}
        },
        
    
        
        safety_policiesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.policy_name)
        },
        safety_policiesOneListFormatter(val) {
            if (!val) return ''
            return val.policy_name
        },
        safety_policiesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.policy_name}
            });
        },
        safety_policiesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.policy_name, id: val.id}
        },
        
    
        
    
        
        ad_projectsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.project_name)
        },
        ad_projectsOneListFormatter(val) {
            if (!val) return ''
            return val.project_name
        },
        ad_projectsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.project_name}
            });
        },
        ad_projectsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.project_name, id: val.id}
        },
        
    
        
    
        
        generation_runsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.model_label)
        },
        generation_runsOneListFormatter(val) {
            if (!val) return ''
            return val.model_label
        },
        generation_runsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.model_label}
            });
        },
        generation_runsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.model_label, id: val.id}
        },
        
    
        
        generation_outputsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.output_title)
        },
        generation_outputsOneListFormatter(val) {
            if (!val) return ''
            return val.output_title
        },
        generation_outputsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.output_title}
            });
        },
        generation_outputsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.output_title, id: val.id}
        },
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
}
