use mogh_resolver::Resolve;
use serde::{Deserialize, Serialize};
use typeshare::typeshare;

use crate::entities::{NoData, ResourceTarget};

use super::KomodoWriteRequest;

//

#[cfg(feature = "utoipa")]
#[utoipa::path(
  post,
  path = "/UpdateResourceMeta",
  description = "Update a resource's common meta fields.",
  request_body(content = UpdateResourceMeta),
  responses(
    (status = 200, description = "Resource meta updated.", body = UpdateResourceMetaResponse),
  ),
)]
pub fn update_resource_meta() {}

/// Update a resources common meta fields.
/// - description
/// - template
/// - tags
/// Response: [NoData].
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoWriteRequest)]
#[response(UpdateResourceMetaResponse)]
#[error(mogh_error::Error)]
pub struct UpdateResourceMeta {
  /// The target resource to set update meta.
  pub target: ResourceTarget,
  /// New description to set,
  /// or null for no update
  pub description: Option<String>,
  /// New template value (true or false),
  /// or null for no update
  pub template: Option<bool>,
  /// The exact tags to set,
  /// or null for no update
  pub tags: Option<Vec<String>>,
}

#[typeshare]
pub type UpdateResourceMetaResponse = NoData;
