// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
generator client {
    provider = "prisma-client-js"
}

generator prismaClassGenerator {
    provider = "prisma-class-generator"
    dryRun   = false
    separateRelationFields = true
}

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

model User {
    id            Int             @id @default(autoincrement())
    username      String          @unique
    password      String?
    email         String?          @unique
    emailVerified Boolean         @default(false)
    googleID      String?         @unique
    isGuest       Boolean         @default(false)
    partyPlayed   Int             @default(0)
    totalScore    Int             @default(0)
    LessonHistory LessonHistory[]
    SongHistory   SongHistory[]
    searchHistory SearchHistory[]
    settings      UserSettings?
    likedSongs    LikedSongs[]
}

model LikedSongs {
    id                   Int        @id @default(autoincrement())
    user                 User       @relation(fields: [userId], references: [id], onDelete: Cascade)
    userId               Int
    song                 Song       @relation(fields: [songId], references: [id], onDelete: Cascade)
    songId               Int
    addedDate            DateTime   @default(now())
}

model UserSettings {
    id                   Int     @id @default(autoincrement())
    user                 User    @relation(fields: [userId], references: [id], onDelete: Cascade)
    userId               Int     @unique
    pushNotification     Boolean @default(true)
    emailNotification    Boolean @default(true)
    trainingNotification Boolean @default(true)
    newSongNotification  Boolean @default(true)
    recommendations      Boolean @default(true)
    weeklyReport         Boolean @default(true)
    leaderBoard          Boolean @default(true)
    showActivity         Boolean @default(true)
}

model SearchHistory {
    id         Int      @id @default(autoincrement())
    query      String
    type       String
    userId     Int?
    user       User?    @relation(fields: [userId], references: [id])
    searchDate DateTime @default(now())
}

model Song {
    id               Int           @id @default(autoincrement())
    name             String        @unique
    midiPath         String
    musicXmlPath     String
    illustrationPath String?
    artistId         Int?
    artist           Artist?       @relation(fields: [artistId], references: [id])
    albumId          Int?
    album            Album?        @relation(fields: [albumId], references: [id])
    genreId          Int?
    genre            Genre?        @relation(fields: [genreId], references: [id])
    difficulties     Json
    SongHistory      SongHistory[]
    likedByUsers     LikedSongs[]
}

model SongHistory {
    id           Int      @id @default(autoincrement())
    song         Song     @relation(fields: [songID], references: [id], onDelete: Cascade, onUpdate: Cascade)
    songID       Int
    user         User     @relation(fields: [userID], references: [id], onDelete: Cascade, onUpdate: Cascade)
    userID       Int
    score        Int
    info         Json
    difficulties Json
    playDate     DateTime @default(now())
}

model Genre {
    id   Int    @id @default(autoincrement())
    name String @unique

    Song Song[]
}

model Artist {
    id   Int    @id @default(autoincrement())
    name String @unique

    Song  Song[]
    Album Album[]
}

model Album {
    id       Int     @id @default(autoincrement())
    name     String  @unique
    artistId Int?
    artist   Artist? @relation(fields: [artistId], references: [id])
    Song     Song[]
}

model Lesson {
    id            Int             @id @default(autoincrement())
    name          String
    description   String
    requiredLevel Int
    mainSkill     Skill
    LessonHistory LessonHistory[]
}

model LessonHistory {
    id       Int    @id @default(autoincrement())
    lesson   Lesson @relation(fields: [lessonID], references: [id])
    lessonID Int
    user     User   @relation(fields: [userID], references: [id])
    userID   Int
}

enum Skill {
    TwoHands
    Rhythm
    NoteCombo
    Arpeggio
    Distance
    LeftHand
    RightHand
    LeadHandChange
    ChordComplexity
    ChordTiming
    Length
    PedalPoint
    Precision

    @@map("DifficultyPoint")
}
