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

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

enum UserRole {
  USER
  ADMIN
}

enum CompanyStatus {
  ACTIVE
  INACTIVE
  SUSPENDED
}

model Company {
  id        Int            @id @default(autoincrement())
  name      String
  status    CompanyStatus  @default(ACTIVE)
  users     User[]
  createdAt DateTime       @default(now())
  updatedAt DateTime       @updatedAt
}

model User {
  id           Int       @id @default(autoincrement())
  email        String    @unique
  password     String
  name         String
  role         UserRole  @default(USER)
  companyId    Int
  company      Company   @relation(fields: [companyId], references: [id])
  refreshToken String?
  orders       Order[]
  createdAt    DateTime  @default(now())
  updatedAt    DateTime  @updatedAt
}

model Product {
  id        Int             @id @default(autoincrement())
  name      String
  sku       String          @unique
  price     Decimal         @db.Decimal(10, 2)
  inventory InventoryItem?
  orders    Order[]
  createdAt DateTime        @default(now())
  updatedAt DateTime        @updatedAt
}

model InventoryItem {
  id        Int      @id @default(autoincrement())
  productId Int      @unique
  product   Product  @relation(fields: [productId], references: [id])
  quantity  Int
  updatedAt DateTime @updatedAt
}

model Order {
  id        Int      @id @default(autoincrement())
  buyerId   Int
  productId Int
  quantity  Int
  total     Decimal  @db.Decimal(12, 2)
  buyer     User     @relation(fields: [buyerId], references: [id])
  product   Product  @relation(fields: [productId], references: [id])
  createdAt DateTime @default(now())
}
