model TonicCountry {
    id         Int      @id @default(autoincrement()) // must have
    createDate DateTime @default(now()) // must have
    updateDate DateTime @updatedAt // must have

    countryCode String
    tonicCountryCode String?
    countryName String
    available   Boolean

    tonicCampaigns TonicCampaign[]

    countryToOfferConnections TonicCountryToOffer[]
    
    tonicHeadlines  TonicHeadline[]

    @@map("tonic_country")
}

model TonicOffer {
    id         Int      @id @default(autoincrement()) // must have
    createDate DateTime @default(now()) // must have
    updateDate DateTime @updatedAt // must have

    offerId   String
    offerName String
    available Boolean

    tonicVericalId Int?
    tonicVertical  TonicVerical? @relation(fields: [tonicVericalId], references: [id])

    tonicCampaigns TonicCampaign[]

    countryToOfferConnections TonicCountryToOffer[]
    names                     String?
    tonicHeadline           TonicHeadline[]

    @@map("tonic_offer")
}



model TonicCampaign {
    id         Int      @id @default(autoincrement()) // must have
    createDate DateTime @default(now()) // must have
    updateDate DateTime @updatedAt // must have

    externalId          String? // tonic
    name                String? // tonic
    status              TonicCampaignStatus? // tonic
    imprint             Boolean? // tonic
    url                 String? // tonic
    target              String? // tonic
    type                String? // tonic
    tonicCreateDate     DateTime?
    searchPanelUserName String?

    offerId           Int?             @unique
    offer             Offer?           @relation(fields: [offerId], references: [id])
    tonicOfferId      Int?
    tonicOffer        TonicOffer?      @relation(fields: [tonicOfferId], references: [id])
    tonicCountryId    Int?
    tonicCountry      TonicCountry?    @relation(fields: [tonicCountryId], references: [id])
    
    providerAccountId Int?             
    providerAccount   ProviderAccount? @relation(fields: [providerAccountId], references: [id])

    tonicHeadlineId     Int?
    tonicHeadline       TonicHeadline? @relation(fields: [tonicHeadlineId], references: [id])

    @@unique([providerAccountId, externalId])
    @@map("tonic_campaign")
}

model TonicHeadline {
    id         Int      @id @default(autoincrement()) // must have
    createDate DateTime @default(now()) // must have
    updateDate DateTime @updatedAt // must have

    tonicOfferId      Int
    tonicOffer        TonicOffer      @relation(fields: [tonicOfferId], references: [id])

    headline          String
    teaser            String?
    externalId        String?
    requestId         Int?

    status            HeadlineStatus @default(PENDING)
    statusDescription String?

    // domain inside
    providerAccountId Int?
    providerAccount   ProviderAccount? @relation(fields: [providerAccountId], references: [id])

    languageId      Int
    language        Language @relation(fields: [languageId], references: [id])

    countryId      Int
    country        TonicCountry @relation(fields: [countryId], references: [id])

    contentGenerationPhrases    TonicContentGenerationPhrase[]

    tonicCampaigns   TonicCampaign[]

    @@map("tonic_headline")
}

model TonicContentGenerationPhrase {
    id         Int      @id @default(autoincrement()) // must have
    createDate DateTime @default(now()) // must have
    updateDate DateTime @updatedAt // must have

    phrase     String

    tonicHeadlineId      Int            @unique
    tonicHeadline        TonicHeadline @relation(fields: [tonicHeadlineId], references: [id])

    @@map("tonic_content_generation_phrase")
    @@unique([phrase, tonicHeadlineId])
}


model TonicVerical {
    id         Int      @id @default(autoincrement()) // must have
    createDate DateTime @default(now()) // must have
    updateDate DateTime @updatedAt // must have

    name      String
    available Boolean

    offers TonicOffer[]

    @@map("tonic_vertical")
}

model TonicCountryToOffer {
    id         Int      @id @default(autoincrement()) // must have
    createDate DateTime @default(now()) // must have
    updateDate DateTime @updatedAt // must have

    offerId   Int
    offer     TonicOffer   @relation(fields: [offerId], references: [id])
    countryId Int
    country   TonicCountry @relation(fields: [countryId], references: [id])

    @@map("tonic_country_to_offer")
}

enum HeadlineStatus {
    NEW
    PENDING
    ACTIVE
    ERROR
    REJECTED
}