model Mission {
    id                         Int                @id @default(autoincrement())
    publicId                   String             @default("")
    type                       missionType        @default(primär)
    state                      MissionState       @default(draft)
    addressLat                 Float
    addressLng                 Float
    addressStreet              String?
    addressCity                String?
    addressZip                 String?
    addressAdditionalInfo      String?            @default("")
    addressMissionLocation     String?            @default("")
    addressOSMways             Json[]             @default([])
    missionKeywordCategory     String
    missionKeywordName         String
    missionKeywordAbbreviation String
    missionPatientInfo         String
    missionAdditionalInfo      String
    missionStationIds          Int[]              @default([])
    missionStationUserIds      String[]           @default([])
    missionLog                 Json[]             @default([])
    hpgMissionString           String?
    hpgSelectedMissionString   String?
    hpgAmbulanceState          HpgState?
    hpgFireEngineState         HpgState?
    hpgPoliceState             HpgState?
    hpgLocationLat             Float?             @default(0)
    hpgLocationLng             Float?             @default(0)
    hpgValidationState         HpgValidationState @default(NOT_VALIDATED)
    createdAt                  DateTime           @default(now())
    updatedAt                  DateTime           @updatedAt
    createdUserId              String

    // relations:

    CreatedUser User @relation(fields: [createdUserId], references: [id])

    MissionsOnStations    MissionsOnStations[]
    MissionOnStationUsers MissionOnStationUsers[]
}

model MissionOnStationUsers {
    userId    String
    missionId Int
    stationId Int

    // relations:
    User    User    @relation(fields: [userId], references: [id])
    Mission Mission @relation(fields: [missionId], references: [id])
    Station Station @relation(fields: [stationId], references: [id])

    @@unique([userId, missionId, stationId])
}

model MissionsOnStations {
    missionId Int
    stationId Int

    // relations:
    Mission Mission @relation(fields: [missionId], references: [id])
    Station Station @relation(fields: [stationId], references: [id])

    @@id([missionId, stationId])
}

enum missionType {
    primär
    sekundär
}

enum MissionState {
    running
    finished
    draft
}

enum HpgState {
    NOT_REQUESTED
    ON_SCENE
    DISPATCHED
}

enum HpgValidationState {
    NOT_VALIDATED
    PENDING
    VALID
    INVALID
    HPG_DISCONNECT
    HPG_BUSY
    HPG_INVALID_MISSION
    POSITION_AMANDED
}
