import type { IUserFields, IUserShort } from './UserStore'

export interface IValidaProd {
  esito?: number
  data?: Date
  username?: string
  note?: string
}

export interface IProductInfo {
  _id?: any
  code?: string
  codice?: string
  id_wp?: string
  sku?: string
  name?: string
  description?: string
  department?: string
  idCatProds?: string[]
  idSubCatProds?: string[]
  catprods?: ICatProd[]
  subcatprods?: ISubCatProd[]
  idStatoProdotto?: number
  color?: string
  size?: string
  weight?: number
  weight_lordo?: number
  unit: number
  unit_lordo?: number
  sfuso?: boolean
  stars?: number
  date?: Date
  icon?: string
  imagefile?: string
  img2?: string
  img3?: string
  img4?: string
  image_link?: string
  ingredienti?: string
  link?: string
  link_scheda?: string
  checkout_link?: string
  valori_nutrizionali?: string
  note?: string
  idAuthors?: string[]
  authors?: string[]
  idCollana?: string
  collana?: ICollana
  idPublisher?: string
  ListaArgomenti?: string
  publisher?: IPublisher
  date_pub?: Date
  date_updated_fromGM?: Date
  date_pub_ts?: number
  pagine?: number
  productTypes?: number[]
  versioneGM?: string
  short_descr?: string

  totVen?: number,
  totFat?: number,
  vLast3M?: number,
  fatLast3M?: number,
  fatLast6M?: number,
  vLast6M?: number,
  vLast1Y?: number,
  vLast2Y?: number,
  dataUltimoOrdine?: Date,
  rank3M?: number,
  rank6M?: number,
  rank1Y?: number,

  descrizione_breve_macro?: string,
  descrizione_completa_macro?: string,
  descr_trafiletto_catalogo?: string,
  sottotitolo?: string,
  link_macro?: string,
}

export interface IVariazione {
  _id?: string
  active?: boolean
  versione?: number
  status?: string,
  price?: number
  sale_price?: number
  quantita?: number
  availability?: number
  formato?: string
  misure?: string
  ristampa?: string
  pagine?: number
  tipologia?: string
  idTipologia?: number
  idTipoFormato?: number
  edizione?: string
  preOrderDate?: Date
  addtocart_link?: string
  eta?: string
  validaprod?: IValidaProd
}

export interface IAuthor {
  _id?: any
  name?: string
  surname?: string
  bio?: string
  img?: string
}

export interface IProdView {
  id: string
}

export interface IOpAndOr {
  condition_andor: number
}

export interface IProduct {
  _id?: any
  active?: boolean
  isbn?: string
  idProductInfo?: string,
  productInfo: IProductInfo,
  idProducer?: string,
  idProvider?: string,
  idStorehouses?: string[],
  idGasordine?: string,
  idScontisticas?: string[],
  scontisticas: IScontistica[],
  producer?: IProducer,
  storehouses: IStorehouse[],
  gasordine: IGasordine | null,
  provider?: IProvider,
  price: number,
  after_price?: string,
  quantityAvailable?: number,
  bookableAvailableQty?: number,
  QuantitaOrdinateInAttesa?: number,
  QuantitaPrenotateInAttesa?: number,
  note?: string
  arrvariazioni?: IVariazione[]

  stockQty: number,           // UPDATING
  stockBloccatiQty: number,   // UPDATING
  bookedQtyOrdered: number  // UPDATING
  bookedQtyConfirmed: number  // UPDATING

  qtyToReachForGas: number
  maxbookableGASQty: number
  bookedGASQtyOrdered: number // UPDATING
  bookedGASQtyConfirmed: number // UPDATING
  bookableGASBloccatiQty: number // UPDATING

  minBuyQty: number
  minStepQty: number
  maxBookableSinglePersQty: number
  canBeShipped?: boolean
  canBeBuyOnline?: boolean
}

export interface IBaseOrder {
  order: IOrder
}

export interface IOrder {
  _id?: any
  idapp?: string
  userId?: string
  status?: number
  idProduct?: string
  idStorehouse?: string
  idGasordine?: string
  TotalPriceProduct: number
  TotalPriceProductCalc: number
  price: number
  after_price?: string
  quantity: number
  quantitypreordered: number
  product?: IProduct
  storehouse?: IStorehouse
  gasordine?: IGasordine
  date_created?: Date
  date_checkout?: Date
  date_payment?: Date
  date_shipping?: Date
  date_delivered?: Date
  notes?: string
  modify_at?: Date
}

export interface IProductsState {
  products: IProduct[]
  authors: IAuthor[]
  publishers: IPublisher[]
  stati_prodotto?: T_Web_StatiProdotto[]
  tipologie?: T_Web_Tipologie[]
  tipoformato?: T_WEB_TipiFormato[]
  cart: ICart
  orders: IOrderCart[]
  catprods: ICatProd[]
  catprtotali?: ICatPrTotali[]
  collane?: ICollana[]
  catprods_gas: ICatProd[]
  subcatprods: ISubCatProd[]
  productInfos: IProductInfo[]
  userActive: IUserShort

  isPubblicatoById?: (idStatoProdotto: number) => boolean;
  isProssimaUscitaById?: (idStatoProdotto: number) => boolean;
  isPrevenditaById?: (idStatoProdotto: number) => boolean;
  isNovitaById?: (date_pub: Date) => boolean;
}

export interface IProducer {
  _id?: any
  idapp?: string
  name?: string
  description?: string
  short_descr?: string
  referent?: string
  username?: string
  region?: string
  city?: string
  img?: string
  website?: string
}

export interface IDepartment {
  _id?: any
  idapp?: string
  name?: string,
  username?: string,
}

export interface ICategory {
  _id?: any
  name: string,
  img?: string,
}

export interface ICatProd {
  _id?: any
  idArgomento?: number,
  name: string,
  descr_estesa?: string,
  img?: string,
  icon?: string,
  color?: string,
}

export interface ICatPrTotali {
  _id: string,
  name: string,
  quanti?: number,
}
export interface ICollaneTotali {
  _id: string,
  title: string,
  quanti?: number,
}

export interface ICollana {
  _id?: any
  idCollana: number,
  title: string,
  quanti?: number,
}

export interface ICatAI {
  _id?: any
  name: string,
  img?: string,
  icon?: string,
  color?: string,
}

export interface IQueryAI {
  _id?: any
  name: string,
  img?: string,
  icon?: string,
  color?: string,
}

export interface IPublisher {
  _id?: any
  idapp?: string
  name?: string
  link?: string
  quanti?: number
}

export interface ISubCatProd {
  _id?: any
  idCatProd: string
  name: string
  img?: string
  icon?: string
  color?: string
}
export interface T_Web_StatiProdotto {
  IdStatoProdotto: number
  Descrizione: string
  dataora?: Date,
  enabled?: boolean
}

export interface T_Web_Tipologie {
  IdTipologia: number
  Descrizione: string
  dataora?: Date,
  enabled?: boolean
}

export interface T_WEB_TipiFormato {
  IdTipoFormato: number
  Descrizione: string
  dataora?: Date,
  enabled?: boolean
}

export interface IStorehouse {
  _id?: any
  idapp?: string
  name?: string,
  username?: string,
  groupname?: string,
  description?: string,
  referent?: string,
  address?: string,
  city?: string,
  region?: string,
  img?: string,
  website?: string,
  email_html_header?: string,
  email_html_footer?: string,
  email_html_makeorder?: string,
  email_html_GAS_makeorder?: string,
  email_html_order_confirmed?: string,
  email_html_GAS_order_confirmed?: string,
  email_html_order_consegnato?: string,
  email_html_GAS_order_consegnato?: string,
}

export interface IProvider {
  _id?: any
  idapp?: string
  name?: string,
  description?: string,
  referent?: string,
  address?: string,
  city?: string,
  region?: string,
  img?: string,
  website?: string,
}

export interface IGasordine {
  _id?: any
  idapp?: string
  active: boolean
  name?: string,
  description?: string,
  referent?: string,
  city?: string,
  img?: string,
  note_ordine_gas?: string
  dataora_chiusura_ordini?: Date,
  data_arrivo_merce?: Date,
  dataora_ritiro?: Date,
}

export interface IScontistica {
  _id?: any
  idapp?: string
  code?: string,
  description?: string,
  qta: number,
  perc_sconto: number,
  price: number,
  comulativo: boolean,
}

export interface ICart {
  _id?: any
  idapp?: string
  userId?: string
  totalQty?: number
  totalPrice?: number
  totalPriceCalc?: number
  department?: string
  items?: IBaseOrder[]
  note?: string
  modify_at?: Date
}

export interface ISingleProductOrdered {
  index: number
  code: string
  codice_interno: string
  idProduct: string
  productName: string
  subCat: string
  strSubCatProds: string
  qty: number
  singlePrice: number
  subtotalPrice: number
}


export interface IOrderCart {
  _id?: any
  idapp?: string
  numorder: number
  numord_pers: number
  userId: string
  user: IUserFields | null,
  totalQty: number
  totalPrice: number
  totalPriceCalc: number
  department?: string
  items?: IBaseOrder[]
  nameSurname?: string
  status: number
  modify_at?: Date
  confermato: boolean
  date_confermato?: Date
  consegnato: boolean
  date_consegnato?: Date
  pagato: boolean
  date_pagato?: Date
  spedito: boolean
  date_spedito?: Date
  ricevuto: boolean
  date_ricevuto?: Date
  created_at?: Date
  note: string
  note_per_gestore: string
  note_per_admin: string
  note_ordine_gas: string
}

export interface IShareWithUs {
  _id?: any
  idapp?: string
  userId?: string
  description: string
  numshared?: number
  rating?: number
}
