// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "mysql"
  url      = env("DATABASE_URL")
}

model Utilisateur {
  ut_id Int @id @default(autoincrement())
  ut_nom String? 
  ut_prenom String?
  ut_mail String @unique
  ut_type_cliente Int?
  ut_age DateTime?
  ut_nb_rdv Int?
  ut_nb_rdv_honores Int?
  ut_prix_moyen Int?
  ut_pdp Int?
  ut_mdp String
  ut_telephone Int?
  ut_date_inscription DateTime @default(now())
  ut_derniere_connexion DateTime?
  ut_slug String?
  commande Commande[]
  achat Achat[]
}

model Formation {
  fo_id Int @id @default(autoincrement())
  fo_titre String?
  fo_description String?
  fo_prix String?
  fo_miniature Bytes?
  fo_teaser String?
  fo_date_publication DateTime @default(now())
  fo_desactive Boolean @default(false)
  fo_slug String?
  fo_video Video[]
  commandeFormation CommandeFormation[]
  achat Achat[]
}

model Video{
  formation Formation @relation(fields: [vi_fo_id],references: [fo_id], onDelete: Cascade)
  vi_fo_id Int
  vi_id Int @id @default(autoincrement())
  vi_titre String?
  vi_description String?
  vi_etape Int?
  vi_url String?
  vi_slug String?
  vi_tv TagVideo[]
}

model Commande{
  co_id Int @id @default(autoincrement())
  co_utilisateur Int
  utilisateur Utilisateur @relation(fields: [co_utilisateur],references: [ut_id])
  co_date_creation DateTime @default(now())
  co_date_update DateTime?
  co_slug String?
  co_status String @default("IN PROGRESS")
}

model CommandeFormation{
  cof_id Int @id @default(autoincrement())
  cof_formation Int
  cof_slug String?
  formation Formation @relation(fields: [cof_formation],references: [fo_id])
}

model Achat{
  ac_id Int @id @default(autoincrement())
  ac_utilisateur Int
  utilisateur Utilisateur @relation(fields: [ac_utilisateur],references: [ut_id])
  ac_formation Int
  formation Formation @relation(fields: [ac_formation],references: [fo_id])
  ac_type String?
  ac_slug String ?
  ac_date_achat DateTime?
  ac_date_fin DateTime?
}

model Tag {
  ta_id Int @id @default(autoincrement())
  ta_titre String?
  ta_slug String?
  vi_tv TagVideo[]
}

model TagVideo{
  @@id([tv_tag_id, tv_video_id])
  tv_tag_id Int 
  tag Tag @relation(fields: [tv_tag_id],references: [ta_id], onDelete: Cascade)
  tv_video_id Int 
  video Video @relation(fields: [tv_video_id],references: [vi_id], onDelete: Cascade)
}

model Session{
  se_id String @id @default(uuid())
  se_ut_id Int 
  createAt DateTime @default(now())
  expireAt DateTime
}
