backup_suite/core/
target.rs

1use clap::ValueEnum;
2use serde::{Deserialize, Serialize};
3use std::path::PathBuf;
4
5/// バックアップの優先度
6///
7/// バックアップ対象の重要度を3段階で定義します。
8/// スケジュール実行時に優先度別の頻度設定が可能です。
9///
10/// # バリアント
11///
12/// * High - 高優先度(毎日バックアップ推奨)
13/// * Medium - 中優先度(週次バックアップ推奨)
14/// * Low - 低優先度(月次バックアップ推奨)
15///
16/// # 使用例
17///
18/// ```no_run
19/// use backup_suite::{Priority, Target};
20/// use std::path::PathBuf;
21///
22/// let target = Target::new(
23///     PathBuf::from("/important/data"),
24///     Priority::High,
25///     "重要データ".to_string()
26/// );
27/// ```
28#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
29#[serde(rename_all = "lowercase")]
30pub enum Priority {
31    Low,
32    Medium,
33    High,
34}
35
36/// バックアップ対象の種別
37///
38/// ファイル単体かディレクトリ全体かを区別します。
39///
40/// # バリアント
41///
42/// * File - 単一ファイル
43/// * Directory - ディレクトリ(配下のファイルを再帰的にバックアップ)
44///
45/// # 使用例
46///
47/// ```no_run
48/// use backup_suite::TargetType;
49///
50/// let file_type = TargetType::File;
51/// let dir_type = TargetType::Directory;
52/// ```
53#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
54#[serde(rename_all = "lowercase")]
55pub enum TargetType {
56    File,
57    Directory,
58}
59
60/// バックアップ対象の定義
61///
62/// バックアップするファイルやディレクトリの情報を保持します。
63///
64/// # フィールド
65///
66/// * `path` - バックアップ対象のパス
67/// * `priority` - 優先度(High/Medium/Low)
68/// * `target_type` - 種別(File/Directory)
69/// * `category` - カテゴリ名(ユーザー定義の分類)
70/// * `added_date` - 設定追加日時
71/// * `exclude_patterns` - 除外する正規表現パターンのリスト
72///
73/// # 使用例
74///
75/// ```no_run
76/// use backup_suite::{Target, Priority};
77/// use std::path::PathBuf;
78///
79/// // 基本的な使用
80/// let mut target = Target::new(
81///     PathBuf::from("/home/user/documents"),
82///     Priority::High,
83///     "重要ドキュメント".to_string()
84/// );
85///
86/// // 除外パターンの追加
87/// target.exclude_patterns = vec![
88///     r"\.tmp$".to_string(),
89///     r"\.log$".to_string(),
90/// ];
91/// ```
92#[derive(Debug, Clone, Serialize, Deserialize)]
93pub struct Target {
94    pub path: PathBuf,
95    pub priority: Priority,
96    pub target_type: TargetType,
97    pub category: String,
98    pub added_date: chrono::DateTime<chrono::Utc>,
99    pub exclude_patterns: Vec<String>,
100}
101
102impl Target {
103    /// 新しいバックアップ対象を作成
104    ///
105    /// パスの種別(ファイル/ディレクトリ)は自動判定されます。
106    ///
107    /// # 引数
108    ///
109    /// * `path` - バックアップ対象のパス
110    /// * `priority` - 優先度
111    /// * `category` - カテゴリ名
112    ///
113    /// # 戻り値
114    ///
115    /// 新しい Target インスタンス
116    ///
117    /// # 使用例
118    ///
119    /// ```no_run
120    /// use backup_suite::{Target, Priority};
121    /// use std::path::PathBuf;
122    ///
123    /// let target = Target::new(
124    ///     PathBuf::from("/home/user/photos"),
125    ///     Priority::Medium,
126    ///     "写真コレクション".to_string()
127    /// );
128    /// ```
129    #[must_use]
130    pub fn new(path: PathBuf, priority: Priority, category: String) -> Self {
131        let target_type = if path.is_file() {
132            TargetType::File
133        } else {
134            TargetType::Directory
135        };
136
137        Self {
138            path,
139            priority,
140            target_type,
141            category,
142            added_date: chrono::Utc::now(),
143            exclude_patterns: vec![],
144        }
145    }
146}