import type { ShareSettings, ShareSettingsWrite, ShareTestResult } from './dto/share'

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

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

    async function saveSettings(payload: ShareSettingsWrite): Promise<ShareSettings> {
        return api.put<ShareSettings>('/settings/share', payload as Record<string, unknown>, {
            toastSuccessKey: 'adminShare.saved',
        })
    }

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

    return { getSettings, saveSettings, testConnection }
}
