Skip to main content

koprogo_api/application/dto/
unit_owner_dto.rs

1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3use validator::Validate;
4
5/// DTO for adding an owner to a unit.
6///
7/// Note : range 0..=1 sur `ownership_percentage` est enforced en domain
8/// (`UnitOwner::new`). validator crate ne supporte pas Decimal sur range
9/// (cf. expense_dto.rs).
10#[derive(Debug, Deserialize, Validate)]
11pub struct AddOwnerToUnitDto {
12    #[validate(length(min = 1))]
13    pub owner_id: String,
14
15    pub ownership_percentage: rust_decimal::Decimal,
16
17    pub is_primary_contact: bool,
18}
19
20/// DTO for updating ownership details.
21/// Range 0..=1 enforced en domain (UnitOwner::update_percentage).
22#[derive(Debug, Deserialize, Validate)]
23pub struct UpdateOwnershipDto {
24    pub ownership_percentage: Option<rust_decimal::Decimal>,
25
26    pub is_primary_contact: Option<bool>,
27}
28
29/// Response DTO for a unit-owner relationship
30#[derive(Debug, Serialize, Clone)]
31pub struct UnitOwnerResponseDto {
32    pub id: String,
33    pub unit_id: String,
34    pub owner_id: String,
35    pub ownership_percentage: rust_decimal::Decimal,
36    pub start_date: DateTime<Utc>,
37    pub end_date: Option<DateTime<Utc>>,
38    pub is_primary_contact: bool,
39    pub is_active: bool,
40    pub created_at: DateTime<Utc>,
41    pub updated_at: DateTime<Utc>,
42}
43
44/// Response DTO for a unit with its owners
45#[derive(Debug, Serialize)]
46pub struct UnitWithOwnersDto {
47    pub unit_id: String,
48    pub unit_number: String,
49    pub floor: Option<i32>,
50    pub area: Option<f64>,
51    pub owners: Vec<UnitOwnerWithDetailsDto>,
52    pub total_ownership_percentage: rust_decimal::Decimal,
53}
54
55/// Response DTO for an owner with their units
56#[derive(Debug, Serialize)]
57pub struct OwnerWithUnitsDto {
58    pub owner_id: String,
59    pub owner_name: String,
60    pub owner_email: String,
61    pub units: Vec<UnitOwnerWithDetailsDto>,
62}
63
64/// Detailed unit-owner relationship with entity details
65#[derive(Debug, Serialize, Clone)]
66pub struct UnitOwnerWithDetailsDto {
67    pub relationship_id: String,
68    pub ownership_percentage: rust_decimal::Decimal,
69    pub is_primary_contact: bool,
70    pub start_date: DateTime<Utc>,
71    pub end_date: Option<DateTime<Utc>>,
72    pub is_active: bool,
73
74    // Unit details (when viewing from owner perspective)
75    pub unit_id: Option<String>,
76    pub unit_number: Option<String>,
77    pub floor: Option<i32>,
78    pub area: Option<f64>,
79    pub building_id: Option<String>,
80
81    // Owner details (when viewing from unit perspective)
82    pub owner_id: Option<String>,
83    pub owner_first_name: Option<String>,
84    pub owner_last_name: Option<String>,
85    pub owner_email: Option<String>,
86    pub owner_phone: Option<String>,
87}
88
89/// DTO for transferring ownership
90#[derive(Debug, Deserialize, Validate)]
91pub struct TransferOwnershipDto {
92    #[validate(length(min = 1))]
93    pub from_owner_id: String,
94
95    #[validate(length(min = 1))]
96    pub to_owner_id: String,
97}