// SPDX-FileCopyrightText: OpenTalk GmbH <mail@opentalk.eu>
// SPDX-License-Identifier: EUPL-1.2

use serde::{Deserialize, Serialize};

use crate::data::{self, ComponentIdentifier, ComponentName, ComponentProfile};

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Component {
    pub identifier: ComponentIdentifier,
    pub name: ComponentName,
    pub gitlab_url: Option<String>,
}

impl Component {
    pub fn from_data_component(
        identifier: ComponentIdentifier,
        component: &data::Component,
        component_profile: &ComponentProfile,
    ) -> Self {
        Self {
            identifier,
            name: component.name.clone(),
            gitlab_url: component_profile.gitlab_url.clone(),
        }
    }
}
