// 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 = "postgresql"
  url      = env("DATABASE_URL")
}

model CommissionType {
  id        String   @id @default(cuid())
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  sortIndex Int      @default(0)

  name String

  description String?

  options CommissionTypeOption[]
  extras  CommissionTypeExtra[]
}

model CommissionOption {
  id        String   @id @default(cuid())
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  sortIndex Int      @default(0)

  name String

  description String?

  types CommissionTypeOption[]
}

model CommissionExtra {
  id        String   @id @default(cuid())
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  sortIndex Int      @default(0)

  name String

  description String?

  types CommissionTypeExtra[]
}

model CommissionTypeOption {
  id        String   @id @default(cuid())
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  sortIndex Int      @default(0)

  typeId   String
  optionId String

  priceRange   String?
  pricePercent Float?
  price        Float?

  type   CommissionType   @relation(fields: [typeId], references: [id])
  option CommissionOption @relation(fields: [optionId], references: [id])

  @@unique([typeId, optionId])
}

model CommissionTypeExtra {
  id        String   @id @default(cuid())
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  sortIndex Int      @default(0)

  typeId  String
  extraId String

  priceRange   String?
  pricePercent Float?
  price        Float?

  type  CommissionType  @relation(fields: [typeId], references: [id])
  extra CommissionExtra @relation(fields: [extraId], references: [id])

  @@unique([typeId, extraId])
}
