import { FileModel, SourceModel } from '@/graphql'

import {
	TbApi,
	TbDatabase,
	TbFileTypeCsv,
	TbFileTypeXls,
	TbFileTypeXml,
	TbJson
} from 'react-icons/tb'

import { DatasetType } from '@/types'

export const getSourceType = (source: SourceModel | FileModel): DatasetType => {
	console.log('source', source);
	
	if ('ext' in source!) {
		return source.ext.toLowerCase() as DatasetType
	}
	//
	if (source.type === 'POLYMATICA') {
		return 'api'
	}
	//
	return 'db'
}

export const getSourceIcon = (type: DatasetType) => {
	switch (type) {
		case 'api':
			return TbApi
		case 'txt':
		case 'csv':
			return TbFileTypeCsv
		case 'xml':
			return TbFileTypeXml
		case 'xls':
		case 'xlsx':
			return TbFileTypeXls
		case 'json':
			return TbJson
		default:
			return TbDatabase
	}
}
