// Prisma schema for Galeria-ALPR License & Updates

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

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

model License {
  id              String       @id @default(uuid())
  key             String       @unique
  email           String
  level           String
  status          String
  expiresAt       DateTime?
  durationMonths  Int?        @default(12)
  lifetime        Boolean      @default(false)
  maxActivations  Int?         @default(3)
  activations     Activation[]
  createdAt       DateTime     @default(now())
  updatedAt       DateTime     @updatedAt
}

model Activation {
  id          String   @id @default(uuid())
  licenseId   String
  deviceId    String
  activatedAt DateTime @default(now())
  lastSeenAt  DateTime?
  license     License  @relation(fields: [licenseId], references: [id], onDelete: Cascade)
}

model Version {
  id             String   @id @default(uuid())
  semver         String
  channel        String
  releaseDate    DateTime @default(now())
  changelog      String
  zipUrl         String
  zipSha256      String
  archiveFilename String?
  previewUrl     String?
  minLicenseLevel String?
  preserveDatabase Boolean @default(true)
  active         Boolean  @default(false)
  createdAt      DateTime @default(now())
}

model InstallerSetting {
  id          Int      @id
  allowStable Boolean  @default(true)
  allowBeta   Boolean  @default(false)
  publicDns   String?
  allowedOrigins String?
  createdAt   DateTime @default(now())
  updatedAt   DateTime @updatedAt
}

model Notification {
  id        String   @id @default(uuid())
  title     String
  message   String
  level     String   @default("info")
  read      Boolean  @default(false)
  createdAt DateTime @default(now())
  readAt    DateTime?
}

model InstallerUser {
  id           String   @id @default(uuid())
  name         String
  email        String   @unique
  passwordHash String
  createdAt    DateTime @default(now())
  updatedAt    DateTime @updatedAt
  lastLoginAt  DateTime?
}

