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

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

/// ---- NextAuth standard models ----
model User {
  id            String   @id @default(cuid())
  name          String?
  email         String?  @unique
  emailVerified DateTime?
  image         String?
  mcName        String?  @unique
  accounts      Account[]
  sessions      Session[]
  posts         Post[]

  availability Availability[]
}

model Account {
  id                 String  @id @default(cuid())
  userId             String
  type               String
  provider           String
  providerAccountId  String
  refresh_token      String?  @db.Text
  access_token       String?  @db.Text
  expires_at         Int?
  id_token           String?  @db.Text
  scope              String?
  token_type         String?
  session_state      String?
  oauth_token_secret String?
  oauth_token        String?

  user User @relation(fields: [userId], references: [id], onDelete: Cascade)

  @@unique([provider, providerAccountId])
}

model Session {
  id           String   @id @default(cuid())
  sessionToken String   @unique
  userId       String
  expires      DateTime

  user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}

model VerificationToken {
  identifier String
  token      String   @unique
  expires    DateTime

  @@unique([identifier, token])
}

/// ---- Example custom model ----
model Post {
  id        String   @id @default(cuid())
  title     String
  content   String?
  createdAt DateTime @default(now())
  authorId  String

  author User @relation(fields: [authorId], references: [id], onDelete: Cascade)
}

model Project {
  id          String   @id @default(cuid())
  joueur      String
  etat        String
  monde       String
  projet      String
  description String
  coords      String?
  tags        String[] @default([])
  createdAt   DateTime @default(now())
}

model Availability {
  id         String   @id @default(cuid())
  userId     String
  day        Int      // 0 = Lundi … 6 = Dimanche
  fromHour   Int      // 0–23
  toHour     Int      // 0–23, > fromHour
  createdAt  DateTime @default(now())

  user       User     @relation(fields: [userId], references: [id])
}