package eu.dnetlib.doiboost

import eu.dnetlib.dhp.schema.common.ModelConstants
import eu.dnetlib.dhp.schema.oaf.{Author, DataInfo}
import eu.dnetlib.dhp.schema.oaf.utils.OafMapperUtils
import org.apache.commons.lang.StringUtils
import eu.dnetlib.dhp.schema.oaf.utils.OafMapperUtils._
import scala.collection.JavaConverters._

object DoiBoostTransformationUtils {


  val TRUST = "0.9"

  def generateDataInfo(): DataInfo = {
    val di = new DataInfo
    di.setDeletedbyinference(false)
    di.setInferred(false)
    di.setInvisible(false)
    di.setTrust(TRUST)
    di.setProvenanceaction(
      OafMapperUtils.qualifier(
        ModelConstants.SYSIMPORT_ACTIONSET,
        ModelConstants.SYSIMPORT_ACTIONSET,
        ModelConstants.DNET_PROVENANCE_ACTIONS,
        ModelConstants.DNET_PROVENANCE_ACTIONS
      )
    )
    di
  }



  def generateOAFAuthor(given: String, family: String, orcid: String, index: Int): Author = {
    val a = new Author
    a.setName(given)
    a.setSurname(family)
    a.setFullname(s"$given $family")
    a.setRank(index + 1)
    if (StringUtils.isNotBlank(orcid))
      a.setPid(
        List(
          structuredProperty(orcid, qualifier(ModelConstants.ORCID_PENDING,ModelConstants.ORCID_PENDING,ModelConstants.DNET_PID_TYPES,ModelConstants.DNET_PID_TYPES), generateDataInfo)
        ).asJava
      )

    a
  }

}
