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

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

model User {
    id    String @id @default(cuid())
    email String @unique
    role  String @default("user")

    createdAt DateTime @default(now())
    updatedAt DateTime @updatedAt

    password         Password?
    favoriteStations UserFavoriteStation[]
}

model Password {
    hash String

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

model Station {
    id          String       @id @default(cuid())
    name        String
    slug        String
    description String?
    imgUrl      String
    streamUrl   String       @unique
    reliability Float
    popularity  Float
    tags        StationTag[]

    createdAt           DateTime              @default(now())
    updatedAt           DateTime              @updatedAt
    UserFavoriteStation UserFavoriteStation[]
}

model Tag {
    id       String       @id @default(cuid())
    name     String       @unique
    slug     String       @unique
    stations StationTag[]

    createdAt DateTime @default(now())
    updatedAt DateTime @updatedAt
}

model StationTag {
    id        String  @id @default(cuid())
    station   Station @relation(fields: [stationId], references: [id])
    tag       Tag     @relation(fields: [tagId], references: [id])
    stationId String
    tagId     String

    createdAt DateTime @default(now())
    updatedAt DateTime @updatedAt
}

model UserFavoriteStation {
    id        String  @id @default(cuid())
    user      User    @relation(fields: [userId], references: [id])
    station   Station @relation(fields: [stationId], references: [id])
    stationId String
    userId    String

    createdAt DateTime @default(now())
    updatedAt DateTime @updatedAt
}

model ContentSource {
    id            String  @id @default(cuid())
    name          String
    type          String
    description   String?
    connectionUrl String  @unique

    createdAt DateTime @default(now())
    updatedAt DateTime @updatedAt
}
