#[cfg(feature = "diesel")]
#[macro_use]
extern crate diesel;

mod country;

use chrono::prelude::*;
pub use country::Country;
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Order {
    pub id: i64,
    #[serde(rename = "orderNumber")]
    pub order_id: String,
    pub origin: String,
    pub locale: String,
    pub date: String,
    pub date_time: DateTime<Utc>,
    pub payment_method: String,
    pub payment_instructions: Option<String>,
    pub currency: String,
    pub shipping_method: String,
    pub shipping_method_name: String,
    pub subtotal: String,
    pub subtotal_cents: i64,
    pub shipping: String,
    pub shipping_cents: i64,
    pub tax: Option<String>,
    pub tax_cents: Option<i64>,
    pub total: String,
    pub total_cents: i64,
    pub email: String,
    pub invoice_address: Address,
    pub shipping_address: Address,
    pub line_items: Vec<LineItem>,
    pub custom_status: String,
    pub shipment: Option<serde_json::Value>,
    pub token: String,

    // other non-order specific view data
    pub today: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct LineItem {
    pub sku: String,
    pub url: String,
    pub name: String,
    pub quantity: i32,
    pub price: String,
    pub price_cents: i64,
    pub taxrate: i32,
    pub total: String,
    pub total_cents: i64,
    pub options: Vec<LineItemOption>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct LineItemOption {
    pub sku: String,
    pub name: String,
    pub value: String,
    pub price: String,
    pub price_cents: i64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Address {
    pub recipient: String,
    pub line1: String,
    pub line2: String,
    pub postal_code: String,
    pub city: String,
    pub province_code: Option<String>,
    pub province_name: Option<String>,
    pub country_code: Country,
    pub country_name: String,
    pub phone: Option<String>,
    pub vat: Option<String>,
}
