import type { ZimbraSettings, ZimbraSettingsWrite, ZimbraTestResult } from './dto/zimbra'

export function useZimbraService() {
    const api = useApi()

    async function getSettings(): Promise<ZimbraSettings> {
        return api.get<ZimbraSettings>('/settings/zimbra')
    }

    async function saveSettings(payload: ZimbraSettingsWrite): Promise<ZimbraSettings> {
        return api.put<ZimbraSettings>('/settings/zimbra', payload as Record<string, unknown>, {
            toastSuccessKey: 'zimbra.settings.saved',
        })
    }

    async function testConnection(): Promise<ZimbraTestResult> {
        return api.post<ZimbraTestResult>('/settings/zimbra/test', {})
    }

    return { getSettings, saveSettings, testConnection }
}
