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

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

model Project {
  id          Int          @id @default(autoincrement())
  name        String
  repository  String
  createdAt   DateTime     @default(now())
  updatedAt   DateTime     @updatedAt
  deployments Deployment[]
  environments Environment[]
}

model Deployment {
  id          Int      @id @default(autoincrement())
  projectId   Int
  project     Project  @relation(fields: [projectId], references: [id])
  environmentId Int
  environment Environment @relation(fields: [environmentId], references: [id])
  status      String   @default("pending") // pending, success, failed
  commitHash  String
  deployedAt  DateTime @default(now())
  logs        String?  @db.Text
}

model Environment {
  id          Int      @id @default(autoincrement())
  name        String
  url         String
  projectId   Int
  project     Project  @relation(fields: [projectId], references: [id])
  deployments Deployment[]
  createdAt   DateTime @default(now())
  updatedAt   DateTime @updatedAt
}

model User {
  id               Int      @id @default(autoincrement())
  email            String   @unique
  password         String
  name             String
  surname          String
  active           Boolean  @default(true)
  role             String   @default("user") // user, admin, etc.
  lastLogin        DateTime?
  createdAt        DateTime @default(now())
  updatedAt        DateTime @updatedAt
  resetToken       String?
  resetTokenExpiry DateTime?
}
