from __future__ import annotations

from datetime import datetime
from typing import Optional

from pydantic import BaseModel, HttpUrl


class ProductBase(BaseModel):
    boutique: str
    url: HttpUrl
    asin: str
    titre: Optional[str]
    url_image: Optional[HttpUrl]
    categorie: Optional[str]
    type: Optional[str]
    actif: Optional[bool] = True


class ProductCreate(ProductBase):
    pass


class ProductUpdate(BaseModel):
    titre: Optional[str] = None
    url_image: Optional[HttpUrl] = None
    categorie: Optional[str] = None
    type: Optional[str] = None
    actif: Optional[bool] = None


class ProductRead(ProductBase):
    id: int
    cree_le: datetime
    modifie_le: datetime

    class Config:
        orm_mode = True


class ProductSnapshotBase(BaseModel):
    prix_actuel: Optional[float]
    prix_conseille: Optional[float]
    prix_min_30j: Optional[float]
    etat_stock: Optional[str]
    en_stock: Optional[bool]
    note: Optional[float]
    nombre_avis: Optional[int]
    prime: Optional[bool]
    choix_amazon: Optional[bool]
    offre_limitee: Optional[bool]
    exclusivite_amazon: Optional[bool]
    statut_scrap: Optional[str]
    message_erreur: Optional[str]


class ProductSnapshotRead(ProductSnapshotBase):
    id: int
    produit_id: int
    scrape_le: datetime

    class Config:
        orm_mode = True
