package models

import models.profile.api._
import slick.lifted.Tag
import com.mohiva.play.silhouette.api.LoginInfo

case class VulnerabilitySubscription(user: LoginInfo, project: String)

class LoginInfoColumns(prefix: String, table: Table[_]) {
  import table.column
  def providerId = column[String](s"${prefix}_provider_id")
  def providerKey = column[String](s"${prefix}_provider_key")
  def apply() = (providerId, providerKey) <> (LoginInfo.tupled, LoginInfo.unapply)
  def === (other: LoginInfo): Rep[Boolean] = (providerId === other.providerID) && (providerKey === other.providerKey)
}

class VulnerabilitySubscriptions(tag: Tag) extends Table[VulnerabilitySubscription](tag, "vulnerability_subscription"){
  val user = new LoginInfoColumns("subscriber", this)
  def project = column[String]("project")
  def * = (user(), project) <> (VulnerabilitySubscription.tupled, VulnerabilitySubscription.unapply)
  def idx = index("all", (user(), project), unique = true)
}