// SPDX-FileCopyrightText: Politik im Blick developers
// SPDX-FileCopyrightText: Wolfgang Silbermayr <wolfgang@silbermayr.at>
//
// SPDX-License-Identifier: AGPL-3.0-or-later OR EUPL-1.2

use serde::{Deserialize, Serialize};

use crate::Updatable;

pub mod get;
pub mod patch;

#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct Profile {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub display_name: Option<String>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub is_superuser: Option<bool>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct UpdateProfile {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub display_name: Option<Option<String>>,
}

impl Updatable for Profile {
    type Update = UpdateProfile;

    fn build_update_from(
        &self,
        Profile {
            display_name,
            is_superuser: _,
        }: &Self,
    ) -> Self::Update {
        let display_name = self.display_name.build_update_from(display_name);
        UpdateProfile { display_name }
    }
}
