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

import kotlinx.serialization.Serializable

/**
 * Wire shapes for the opt-in push surface under `/auth/me` (PLAN.md §11, M7
 * Part 2). Field names match the backend's `notifications.controller` /
 * `pushDevices.model` exactly; every DTO ignores unknown keys (NetworkModule's
 * lenient Json), so additive backend fields are safe (recorded for M1).
 */

/**
 * `POST /auth/me/devices` body. [endpoint] is the ntfy topic URL the app's
 * embedded distributor owns (`https://<ntfy-host>/<topic>`); the backend
 * SSRF-validates it is HTTPS on the shard's allow-set before storing. [transport]
 * is `unifiedpush` for the direct-ntfy relay (fcm reserved for a future flavor).
 */
@Serializable
data class RegisterDeviceRequest(
    val endpoint: String,
    val transport: String = "unifiedpush",
    val platform: String? = null,
)

/** `POST/GET /auth/me/devices` — one registered device (endpoint) for this user. */
@Serializable
data class PushDeviceDto(
    val id: Long = 0,
    val transport: String = "",
    val endpoint: String = "",
    val platform: String? = null,
    val createdAt: String? = null,
    val lastSeenAt: String? = null,
)

/**
 * One subscribable stream from `GET /auth/me/notifications/streams`. A [personal]
 * stream is delivered only to the owning user and [requiresLinkedAccount] — the app
 * greys its toggle until a game account is linked (§11).
 */
@Serializable
data class NotificationStreamDto(
    val id: String = "",
    val label: String = "",
    val description: String = "",
    val personal: Boolean = false,
    val requiresLinkedAccount: Boolean = false,
)

/** `GET /auth/me/notifications/streams` — the catalog. */
@Serializable
data class NotificationStreamsDto(
    val streams: List<NotificationStreamDto> = emptyList(),
)

/**
 * `GET/PUT /auth/me/notifications/subscriptions` — the user's opted-in stream ids.
 * PUT replaces the full set; unknown ids are dropped server-side and the stored set
 * echoed back.
 *
 * [streams] intentionally has NO default: this DTO doubles as the PUT body, and the
 * backend validator requires the `streams` field (`body('streams').isArray()`).
 * kotlinx omits a property equal to its default (encodeDefaults=false), so a default
 * of `emptyList()` would drop the field when the user clears their LAST subscription,
 * sending `{}` → 400 "Validation failed" (the "can't turn off the last one" bug). With
 * no default the empty list always serializes as `{"streams":[]}`. Do not re-add a default.
 */
@Serializable
data class NotificationSubscriptionsDto(
    val streams: List<String>,
)
