/*
 * SPDX-License-Identifier: GPL-3.0-or-later
 */
package com.runicgateway.app.data.repository

import com.runicgateway.app.core.result.ApiResult
import com.runicgateway.app.core.result.safeApiCall
import com.runicgateway.app.data.api.PublicApi
import com.runicgateway.app.data.api.dto.ContactRequest
import com.runicgateway.app.data.api.dto.ContactResponse
import javax.inject.Inject
import javax.inject.Singleton

/**
 * Contact form submission (PLAN.md §6.1). The endpoint is rate-limited; the
 * caller handles `429` (too many) and `502` (mailer down) via [ApiResult.HttpError].
 */
@Singleton
class ContactRepository @Inject constructor(
    private val api: PublicApi,
) {
    suspend fun send(name: String, email: String, message: String): ApiResult<ContactResponse> =
        safeApiCall { api.postContact(ContactRequest(name = name, email = email, message = message)) }
}
