use diesel::{AsChangeset, Identifiable, Insertable, Queryable, Selectable};
use time::PrimitiveDateTime;

use crate::{enums as storage_enums, schema::cards_info};

#[derive(
    Clone,
    Debug,
    Queryable,
    Identifiable,
    Selectable,
    serde::Deserialize,
    serde::Serialize,
    Insertable,
)]
#[diesel(table_name = cards_info, primary_key(card_iin), check_for_backend(diesel::pg::Pg))]
pub struct CardInfo {
    pub card_iin: String,
    pub card_issuer: Option<String>,
    pub card_network: Option<storage_enums::CardNetwork>,
    pub card_type: Option<String>,
    pub card_subtype: Option<String>,
    pub card_issuing_country: Option<String>,
    pub bank_code_id: Option<String>,
    pub bank_code: Option<String>,
    pub country_code: Option<String>,
    pub date_created: PrimitiveDateTime,
    pub last_updated: Option<PrimitiveDateTime>,
    pub last_updated_provider: Option<String>,
    pub funding_source: Option<storage_enums::FundingSource>,
    pub card_iin_type: Option<storage_enums::PanOrToken>,
    pub virtual_card: Option<bool>,
    pub gambling_blocked: Option<bool>,
    pub co_badged_card_networks: Option<common_utils::types::CoBadgedCardNetworkMetadata>,
    pub card_segment_type: Option<String>,
    pub numeric_country_code: Option<String>,
    pub prepaid: Option<bool>,
    pub regulated: Option<bool>,
    pub issuer_phone: Option<String>,
    pub issuer_url: Option<String>,
    pub regulated_name: Option<String>,
    pub reloadable_prepaid: Option<bool>,
    pub account_updater: Option<bool>,
    pub account_level_management: Option<bool>,
    pub domestic_only: Option<bool>,
    pub level_two_supported: Option<bool>,
    pub level_three_supported: Option<bool>,
    pub issuer_currency: Option<String>,
    pub combo_card: Option<String>,
    pub authentication: Option<common_utils::types::CardAuthentication>,
    pub cost: Option<common_utils::types::CardCost>,
    pub issuer_supports_tokenization: Option<bool>,
    pub billpay_enabled: Option<bool>,
    pub ecom_enabled: Option<bool>,
    pub flexible_credential_supported: Option<bool>,
    pub card_subtype_code: Option<String>,
    pub multi_account_access_indicator: Option<String>,
}

#[derive(
    Clone, Debug, PartialEq, Eq, AsChangeset, router_derive::DebugAsDisplay, serde::Deserialize,
)]
#[diesel(table_name = cards_info)]
pub struct UpdateCardInfo {
    pub card_issuer: Option<String>,
    pub card_network: Option<storage_enums::CardNetwork>,
    pub card_type: Option<String>,
    pub card_subtype: Option<String>,
    pub card_issuing_country: Option<String>,
    pub bank_code_id: Option<String>,
    pub bank_code: Option<String>,
    pub country_code: Option<String>,
    pub last_updated: Option<PrimitiveDateTime>,
    pub last_updated_provider: Option<String>,
    pub funding_source: Option<storage_enums::FundingSource>,
    pub card_iin_type: Option<storage_enums::PanOrToken>,
    pub virtual_card: Option<bool>,
    pub gambling_blocked: Option<bool>,
    pub co_badged_card_networks: Option<common_utils::types::CoBadgedCardNetworkMetadata>,
    pub card_segment_type: Option<String>,
    pub numeric_country_code: Option<String>,
    pub prepaid: Option<bool>,
    pub regulated: Option<bool>,
    pub issuer_phone: Option<String>,
    pub issuer_url: Option<String>,
    pub regulated_name: Option<String>,
    pub reloadable_prepaid: Option<bool>,
    pub account_updater: Option<bool>,
    pub account_level_management: Option<bool>,
    pub domestic_only: Option<bool>,
    pub level_two_supported: Option<bool>,
    pub level_three_supported: Option<bool>,
    pub issuer_currency: Option<String>,
    pub combo_card: Option<String>,
    pub authentication: Option<common_utils::types::CardAuthentication>,
    pub cost: Option<common_utils::types::CardCost>,
    pub issuer_supports_tokenization: Option<bool>,
    pub billpay_enabled: Option<bool>,
    pub ecom_enabled: Option<bool>,
    pub flexible_credential_supported: Option<bool>,
    pub card_subtype_code: Option<String>,
    pub multi_account_access_indicator: Option<String>,
}
