use serde::{Deserialize, Serialize};
use bigdecimal::BigDecimal;
use chrono::NaiveDateTime;
use sqlx::FromRow;

#[derive(Deserialize)]
pub struct RegistrationData {
    pub email: String,
    pub haslo: String,
    pub imie: String,
    #[serde(rename = "confirmPassword")]
    pub confirm_password: String,
}

#[derive(Deserialize)]
pub struct LoginData {
    pub email: String,
    pub haslo: String,
}

#[derive(Serialize)]
pub struct LoginResponse {
    pub token: String,
    pub imie: String,
}

#[derive(sqlx::FromRow, Serialize)]
pub struct Book {
    pub id: i32,
    pub tytul: String,
    pub autor: String,
    pub cena: BigDecimal,
    pub obraz_url: Option<String>,
    pub opis: Option<String>,
}

#[derive(Deserialize)]
pub struct CartItem {
    pub book_id: i32,
    pub quantity: i32,
}

#[derive(Serialize)]
pub struct CartItemResponse {
    pub book_id: i32,
    pub quantity: i32,
    pub tytul: String,
    pub cena: BigDecimal,
    #[serde(rename = "obraz_url")]
    pub obraz_url: String,
}

#[derive(Serialize, FromRow)]
pub struct OrderItem {
    pub tytul: String,
    pub autor: String,
    pub ilosc: i32,
    pub cena: BigDecimal,
}

#[derive(Serialize)]
pub struct OrderWithItems {
    pub id: i32,
    pub data_zamowienia: NaiveDateTime,
    pub suma_totalna: BigDecimal,
    pub status: Option<String>,
    pub items: Vec<OrderItem>,
}

#[derive(Deserialize)]
pub struct CartQuantityUpdate {
    pub book_id: i32,
    pub change: i32,
}

#[derive(Deserialize)]
pub struct CheckoutRequest {
    pub items: Vec<CartItem>,
    pub total: f64,
    pub delivery_type: String,
}
