use serde::{Serialize, Deserialize};
use super::{PlaidError, Products};
///Metadata about the Item.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Item {
///A list of products available for the Item that have not yet been accessed. The contents of this array will be mutually exclusive with `billed_products`.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub available_products: Vec<Products>,
///A list of products that have been billed for the Item. The contents of this array will be mutually exclusive with `available_products`. Note - `billed_products` is populated in all environments but only requests in Production are billed. Also note that products that are billed on a pay-per-call basis rather than a pay-per-Item basis, such as `balance`, will not appear here.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub billed_products: Vec<Products>,
///The date and time at which the Item's access consent will expire, in [ISO 8601](https://wikipedia.org/wiki/ISO_8601) format
#[serde(default, skip_serializing_if = "Option::is_none")]
pub consent_expiration_time: Option<chrono::DateTime<chrono::Utc>>,
///A list of products that the user has consented to for the Item via [Data Transparency Messaging](/docs/link/data-transparency-messaging-migration-guide). This will consist of all products where both of the following are true: the user has consented to the required data scopes for that product and you have Production access for that product.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub consented_products: Option<Vec<Products>>,
///Errors are identified by `error_code` and categorized by `error_type`. Use these in preference to HTTP status codes to identify and handle specific errors. HTTP status codes are set and provide the broadest categorization of errors: 4xx codes are for developer- or user-related errors, and 5xx codes are for Plaid-related errors, and the status will be 2xx in non-error cases. An Item with a non-`null` error object will only be part of an API response when calling `/item/get` to view Item status. Otherwise, error fields will be `null` if no error has occurred; if an error has occurred, an error code will be returned instead.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub error: Option<PlaidError>,
///The Plaid Institution ID associated with the Item. Field is `null` for Items created via Same Day Micro-deposits.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub institution_id: Option<String>,
///The Plaid Item ID. The `item_id` is always unique; linking the same account at the same institution twice will result in two Items with different `item_id` values. Like all Plaid identifiers, the `item_id` is case-sensitive.
pub item_id: String,
///A list of products added to the Item. In almost all cases, this will be the same as the `billed_products` field. For some products, it is possible for the product to be added to an Item but not yet billed (e.g. Assets, before `/asset_report/create` has been called, or Auth or Identity when added as Optional Products but before their endpoints have been called), in which case the product may appear in `products` but not in `billed_products`.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub products: Option<Vec<Products>>,
/**Indicates whether an Item requires user interaction to be updated, which can be the case for Items with some forms of two-factor authentication.
`background` - Item can be updated in the background
`user_present_required` - Item requires user interaction to be updated*/
pub update_type: String,
///The URL registered to receive webhooks for the Item.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub webhook: Option<String>,
}
impl std::fmt::Display for Item {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
write!(f, "{}", serde_json::to_string(self).unwrap())
}
}