use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum MarketOrderType {
  Buy,
  Sell,
  All,
}

impl ToString for MarketOrderType {
  fn to_string(&self) -> String {
    match self {
      MarketOrderType::Buy => "buy".to_string(),
      MarketOrderType::Sell => "sell".to_string(),
      MarketOrderType::All => "all".to_string(),
    }
  }
}

#[derive(Debug, Serialize, Deserialize)]
pub struct CharacterMarketOrder {
  pub duration: i32,
  pub escrow: Option<f32>,
  pub is_buy_order: Option<bool>,
  pub is_corporation: bool,
  pub issued: DateTime<Utc>,
  pub location_id: i64,
  pub min_volume: Option<i32>,
  pub order_id: i64,
  pub price: f32,
  pub range: String,
  pub region_id: i32,
  pub state: Option<String>, // "cancelled" or "expired", required on history endpoint
  pub type_id: i32,
  pub volume_remain: f32,
  pub volume_total: f32,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct CorporationMarketOrder {
  pub duration: i32,
  pub escrow: Option<f32>,
  pub is_buy_order: Option<bool>,
  pub issued: DateTime<Utc>,
  pub location_id: i64,
  pub min_volume: Option<i32>,
  pub order_id: i64,
  pub price: f32,
  pub range: String,
  pub region_id: i32,
  pub state: Option<String>, // "cancelled" or "expired", required on history endpoint
  pub type_id: i32,
  pub volume_remain: f32,
  pub volume_total: f32,
  pub wallet_division: i32,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct MarketOrder {
  pub duration: i32,
  pub is_buy_order: bool,
  pub issued: DateTime<Utc>,
  pub location_id: i64,
  pub min_volume: i32,
  pub order_id: i64,
  pub price: f32,
  pub range: String,
  pub system_id: i32,
  pub type_id: i32,
  pub volume_remain: f32,
  pub volume_total: f32,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct MarketHistory {
  pub average: f32,
  pub date: String,
  pub highest: f32,
  pub lowest: f32,
  pub order_count: i32,
  pub volume: i64,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct MarketGroup {
  pub description: String,
  pub market_group_id: i32,
  pub name: String,
  pub parent_group_id: Option<i32>,
  pub types: Vec<i32>,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct MarketPrice {
  pub adjusted_price: Option<f32>,
  pub average_price: Option<f32>,
  pub type_id: i32,
}
