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}
        },
        
    
        
        organizationsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        organizationsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        organizationsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        organizationsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        locationsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        locationsOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        locationsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        locationsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
    
        
        payersManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        payersOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        payersManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        payersOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        payer_plansManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        payer_plansOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        payer_plansManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        payer_plansOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        procedure_familiesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        procedure_familiesOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        procedure_familiesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        procedure_familiesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        cpt_codesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.code)
        },
        cpt_codesOneListFormatter(val) {
            if (!val) return ''
            return val.code
        },
        cpt_codesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.code}
            });
        },
        cpt_codesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.code, id: val.id}
        },
        
    
        
        patientsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.last_name)
        },
        patientsOneListFormatter(val) {
            if (!val) return ''
            return val.last_name
        },
        patientsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.last_name}
            });
        },
        patientsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.last_name, id: val.id}
        },
        
    
        
        authorization_casesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.site_of_service)
        },
        authorization_casesOneListFormatter(val) {
            if (!val) return ''
            return val.site_of_service
        },
        authorization_casesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.site_of_service}
            });
        },
        authorization_casesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.site_of_service, id: val.id}
        },
        
    
        
        case_documentsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.original_filename)
        },
        case_documentsOneListFormatter(val) {
            if (!val) return ''
            return val.original_filename
        },
        case_documentsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.original_filename}
            });
        },
        case_documentsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.original_filename, id: val.id}
        },
        
    
        
        submissionsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.reference_number)
        },
        submissionsOneListFormatter(val) {
            if (!val) return ''
            return val.reference_number
        },
        submissionsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.reference_number}
            });
        },
        submissionsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.reference_number, id: val.id}
        },
        
    
        
    
        
    
        
        denialsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.denial_code)
        },
        denialsOneListFormatter(val) {
            if (!val) return ''
            return val.denial_code
        },
        denialsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.denial_code}
            });
        },
        denialsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.denial_code, id: val.id}
        },
        
    
        
    
        
        templatesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.name)
        },
        templatesOneListFormatter(val) {
            if (!val) return ''
            return val.name
        },
        templatesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.name}
            });
        },
        templatesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.name, id: val.id}
        },
        
    
        
        payer_rulesManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.version_label)
        },
        payer_rulesOneListFormatter(val) {
            if (!val) return ''
            return val.version_label
        },
        payer_rulesManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.version_label}
            });
        },
        payer_rulesOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.version_label, id: val.id}
        },
        
    
        
    
        
        ai_jobsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.model_ref)
        },
        ai_jobsOneListFormatter(val) {
            if (!val) return ''
            return val.model_ref
        },
        ai_jobsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.model_ref}
            });
        },
        ai_jobsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.model_ref, id: val.id}
        },
        
    
        
        ai_outputsManyListFormatter(val) {
            if (!val || !val.length) return []
            return val.map((item) => item.model_ref)
        },
        ai_outputsOneListFormatter(val) {
            if (!val) return ''
            return val.model_ref
        },
        ai_outputsManyListFormatterEdit(val) {
            if (!val || !val.length) return []
            return val.map((item) => {
              return {id: item.id, label: item.model_ref}
            });
        },
        ai_outputsOneListFormatterEdit(val) {
            if (!val) return ''
            return {label: val.model_ref, id: val.id}
        },
        
    
        
    
        
    
        
    
        
    
}
