backbone_banking/domain/entity/
source_format.rs1use serde::{Deserialize, Serialize};
2use sqlx::Type;
3use std::str::FromStr;
4#[cfg(feature = "openapi")]
5use utoipa::ToSchema;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Type)]
8#[cfg_attr(feature = "openapi", derive(ToSchema))]
9#[serde(rename_all = "snake_case")]
10#[sqlx(type_name = "source_format", rename_all = "snake_case")]
11pub enum SourceFormat {
12 Manual,
13 Csv,
14 Mt940,
15 Camt053,
16 Api,
17}
18
19impl std::fmt::Display for SourceFormat {
20 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21 match self {
22 Self::Manual => write!(f, "manual"),
23 Self::Csv => write!(f, "csv"),
24 Self::Mt940 => write!(f, "mt940"),
25 Self::Camt053 => write!(f, "camt053"),
26 Self::Api => write!(f, "api"),
27 }
28 }
29}
30
31impl FromStr for SourceFormat {
32 type Err = String;
33
34 fn from_str(s: &str) -> Result<Self, Self::Err> {
35 match s.to_lowercase().as_str() {
36 "manual" => Ok(Self::Manual),
37 "csv" => Ok(Self::Csv),
38 "mt940" => Ok(Self::Mt940),
39 "camt053" => Ok(Self::Camt053),
40 "api" => Ok(Self::Api),
41 _ => Err(format!("Unknown SourceFormat variant: {}", s)),
42 }
43 }
44}
45
46impl Default for SourceFormat {
47 fn default() -> Self {
48 Self::Manual
49 }
50}