/*
 * asklyphe-common nats/authservice/announcements.rs
 * - nats structs for reading announcements
 *
 * Copyright (C) 2025 Real Microsoft, LLC
 *
 * This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, version 3.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

// announcements are also sometimes referred to as "notes"

use serde::{Deserialize, Serialize};

/// # LatestAnnouncementRequest
/// sent from frontend -> authsrvc, returns the latest announcement in its short form
/// expecting an AuthServiceResponse::LatestAnnouncementResponse back
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LatestAnnouncementRequest {}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AnnouncementShortForm {
    pub title: String,
    pub short_text: String,
    pub date: i64, // unix utc
    pub slug: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum LatestAnnouncementResponse {
    Some(AnnouncementShortForm),
    None,
    InternalServerError(String),
}

/// # AnnouncementListRequest
/// sent from frontend -> authsrvc,
/// returns a list of all announcements in order of newest first to oldest last
/// expecting an AuthServiceResponse::AnnouncementListResponse back
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AnnouncementListRequest {
    pub limit: Option<usize>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum AnnouncementListResponse {
    Success(Vec<AnnouncementShortForm>),
    InternalServerError(String),
}

/// # AnnouncementFullRequest
/// sent from frontend -> authsrvc, returns the full contents of an announcement
/// expecting an AuthServiceResponse::AnnouncementFullResponse back
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AnnouncementFullRequest {
    pub slug: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AnnouncementFull {
    pub title: String,
    pub created_on: i64,
    pub updated_on: Option<i64>,
    pub slug: String,
    pub creator: String, // username
    pub markdown_text: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum AnnouncementFullResponse {
    Some(AnnouncementFull),
    NotFound,
    InternalServerError(String),
}