// 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"
  output   = "../app/generated/prisma"
}

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

// user
model User {
  id          String   @id @default(uuid())
  email       String
  icon        String @default("")
  isApproved  Boolean  @default(false)
  createtime  DateTime @default(now())
  RegisgerCode      String @default("")

  // Many-to-many: a user can have many handles
  handles     Handle[]
  // One-to-many: a user can have many register channels
  registerChannels RegisterChannel[]
}

model RegisterChannel {
  id          String   @id @default(uuid())
  handle      String
  // Relation: many register channels belong to one user
  userId      String
  user        User     @relation(fields: [userId], references: [id])
}

// handle
model Handle {
  id        String   @id @default(uuid())
  handle    String   @unique
  avatar   String @default("")
  costPerView Float @default(1)
  // Relations
  contents  Content[]
  // Many-to-many: a handle can belong to many users
  users     User[]
}

// content
model Content{
  id             String   @id @default(uuid())
  subject        String
  pubDate        DateTime
  // views          Int
  // validViews     Int
  // premiumViews   Int
  // watchTime      Int
  // Relation: many contents belong to one handle
  handleId       String?
  handle         Handle?  @relation(fields: [handleId], references: [id])
  // Back relation: one content has many day views
  dayViews       ContentDayView[]
}

model ContentDayView{
  id        String   @id @default(uuid())
  contentId String
  date DateTime
  views Int
  validViews Int
  premiumViews Int
  watchTime Int
  // Relation: many day views belong to one content
  content   Content  @relation(fields: [contentId], references: [id])
  @@unique([contentId, date])
}


// notice
model noticeBoard{
  id        String   @id @default(uuid())
  title     String
  content   String @db.LongText
  tag      String
  pubDate   DateTime
  isDeleted Boolean @default(false)
}



/*
  npx prisma migrate dev --name <migration_name>
   새로운 마이그레이션 파일 생성
  npx prisma generate
    프리즈마 클라이언트 생성
  npx prisma db push 
    데이터베이스 동기화
  npx prisma studio
*/


