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