1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
//! # Firebase Rust SDK
//! The Firebase Rust SDK provides a convenient way to interact with Firebase services in Rust applications. This README provides an overview of the SDK and guides you on how to use it effectively.
//! ## Usage
//! To interact with Firebase services, you need to create an `App` instance with the required options. Here's an example:
//! ```rust
//! use firebase_app_sdk::{App,DEFAULT,Options};
//! 
//! fn main() {
//!     let options = Options::new("YOUR_APPLICATION_ID", "YOUR_API_KEY")
//!         .with_database_url("YOUR_DATABASE_URL")
//!         .with_storage_bucket("YOUR_STORAGE_BUCKET");
//!     
//!     let app = App::new(DEFAULT, options);
//! }
//! ```
//! Once you have created an App instance, you can pass it to other Firebase services for further interactions. Here's an example of using the app instance with the Firebase Authentication service:
//!
//! ```rust
//! use firebase_app_sdk::App;
//! use firebase_app_sdk::Options;
//! use firebase_auth_sdk::auth::Authentication;
//! 
//! const DEFAULT: &str = "DEFAULT";
//! 
//! fn main() {
//!     let options = Options::new("YOUR_APPLICATION_ID", "YOUR_API_KEY")
//!         .with_auth_domain("YOUR_AUTH_DOMAIN");
//!     
//!     let app = App::new(DEFAULT, options);
//!     
//!     // Use the app instance with the Firebase Authentication service
//!     let auth = Authentication::new(&app);
//!     
//!     // Perform authentication operations using the `auth` instance
//!    // ...
//! }
//! ```
//! Please note that the above examples are simplified and serve as a starting point. Refer to the documentation of each Firebase service for detailed usage instructions.

///Represents a default value or identifier in the context of the Firebase application.
pub const DEFAULT : &str = "DEFAULT";

/// Represents an application with its associated options.
pub struct App<'a> {
    /// The name of the application.
    pub name: &'a str,
    /// The options for the application.
    pub options: Options<'a>,
}

/// Represents the configurable options for an application.
pub struct Options<'a> {
    /// The application ID.
    pub application_id: &'a str,
    /// The API key for accessing the application.
    pub api_key: &'a str,
    /// The URL of the database (optional).
    pub database_url: Option<&'a str>,
    /// The Google Analytics tracking ID (optional).
    pub ga_tracking_id: Option<&'a str>,
    /// The storage bucket (optional).
    pub storage_bucket: Option<&'a str>,
    /// The project ID (optional).
    pub project_id: Option<&'a str>,
    /// The Google Cloud Messaging (GCM) sender ID (optional).
    pub gcm_sender_id: Option<&'a str>,
    /// The authentication domain (optional).
    pub auth_domain: Option<&'a str>,
}

impl<'a> App<'a> {
    /// Creates a new instance of the `App` struct.
    ///
    /// # Arguments
    ///
    /// * `name` - The name of the application.
    /// * `options` - The options for the application.
    ///
    /// # Returns
    ///
    /// A new `App` instance.
    pub fn new(name: &'a str, options: Options<'a>) -> Self {
        /*let db : Database = open_database(DATABASE_NAME).unwrap();

        if name != DEFAULT && db.contains_key(DEFAULT).unwrap_or(false) {
            return Err("Error: Database does not contain default value".to_string());
        };

        if db.contains_key(name).unwrap_or(false) {
            return Err(format!("Error: Database already contains app named [{}] ",name));
        };

        let app = App {
            name,
            options,
        };

        let serialized = serde_json::to_string(&app).expect("Error serializing app");
        let bytes = serialized.as_bytes();

        db.insert(name,SledVector::from(bytes)).expect("Error writing app instance to database");*/
        App {
            name,
            options,
        }
    }
}

impl<'a> Options<'a> {
    /// Creates a new instance of the `Options` struct.
    ///
    /// # Arguments
    ///
    /// * `application_id` - The application ID.
    /// * `api_key` - The API key for accessing the application.
    ///
    /// # Returns
    ///
    /// A new `Options` instance.
    pub const fn new(application_id: &'a str, api_key: &'a str) -> Self {
        Options {
            application_id,
            api_key,
            database_url: None,
            ga_tracking_id: None,
            storage_bucket: None,
            project_id: None,
            gcm_sender_id: None,
            auth_domain: None,
        }
    }

    /// Sets the database URL for the options.
    ///
    /// # Arguments
    ///
    /// * `database_url` - The URL of the database.
    ///
    /// # Returns
    ///
    /// The modified `Options` instance.
    pub const fn with_database_url(mut self, database_url: &'a str) -> Self {
        self.database_url = Some(database_url);
        self
    }

    /// Sets the Google Analytics tracking ID for the options.
    ///
    /// # Arguments
    ///
    /// * `ga_tracking_id` - The Google Analytics tracking ID.
    ///
    /// # Returns
    ///
    /// The modified `Options` instance.
    pub const fn with_ga_tracking_id(mut self, ga_tracking_id: &'a str) -> Self {
        self.ga_tracking_id = Some(ga_tracking_id);
        self
    }

    /// Sets the storage bucket for the options.
    ///
    /// # Arguments
    ///
    /// * `storage_bucket` - The storage bucket.
    ///
    /// # Returns
    ///
    /// The modified `Options` instance.
    pub const fn with_storage_bucket(mut self, storage_bucket: &'a str) -> Self {
        self.storage_bucket = Some(storage_bucket);
        self
    }

    /// Sets the project ID for the options.
    ///
    /// # Arguments
    ///
    /// * `project_id` - The project ID.
    ///
    /// # Returns
    ///
    /// The modified `Options` instance.
    pub const fn with_project_id(mut self, project_id: &'a str) -> Self {
        self.project_id = Some(project_id);
        self
    }

    /// Sets the Google Cloud Messaging (GCM) sender ID for the options.
    ///
    /// # Arguments
    ///
    /// * `gcm_sender_id` - The GCM sender ID.
    ///
    /// # Returns
    ///
    /// The modified `Options` instance.
    pub const fn with_gcm_sender_id(mut self, gcm_sender_id: &'a str) -> Self {
        self.gcm_sender_id = Some(gcm_sender_id);
        self
    }

    /// Sets the authentication domain for the options.
    ///
    /// # Arguments
    ///
    /// * `auth_domain` - The authentication domain.
    ///
    /// # Returns
    ///
    /// The modified `Options` instance.
    pub const fn with_auth_domain(mut self, auth_domain: &'a str) -> Self {
        self.auth_domain = Some(auth_domain);
        self
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn create_app_instance(){
        App::new(DEFAULT,Options::new("..","..."));
    }
}