//! D-Bus surface types for `org.liberux.CallLog1`. Kept separate from the
//! `crate::model` domain types so the wire representation can evolve
//! independently (NULL `cached_name` rounds to the empty string, i64 ids are
//! clamped to u32).

use serde::{ Deserialize, Serialize };
use zbus::zvariant::Type;

use crate::model::Call;

/// Wire signature: `(usxxibs)` —
/// `(id, number, date, duration, type, new, cached_name)`.
#[ derive( Debug, Clone, Serialize, Deserialize, Type ) ]
pub struct CallDbus
{
	pub id: u32,
	pub number: String,
	pub date: i64,
	pub duration: i64,
	pub call_type: i32,
	pub new: bool,
	pub cached_name: String,
}

impl From<Call> for CallDbus
{
	fn from( c: Call ) -> Self
	{
		Self
		{
			id:          c.id as u32,
			number:      c.number,
			date:        c.date,
			duration:    c.duration,
			call_type:   c.call_type,
			new:         c.new,
			cached_name: c.cached_name.unwrap_or_default(),
		}
	}
}
