<commit_before>package models

import play.api.cache.Cache
import play.api.mvc.{Action, Result, AnyContent, Request}

case class Claim(sections: Map[String, Section] = Map()) extends CreationTimeStamp {

  def section(sectionId: String): Option[Section] = {
    sections.get(sectionId)
  }

  /*def getNextIncompleteSection: Option[Section] = {
    sections.find(section => !section.isComplete)
  }

  def findSectionForClaim(sectionId: String, claim: Claim) = {
    claim.sections.find(section => section.id.equals(sectionId))
  }

  def findQuestionGroupForSection(sectionId: String, questionGroupId: String, claim: Claim) = {
    val sectionOption = findSectionForClaim(sectionId, claim)
    sectionOption.get.forms.find(questionGroup => questionGroup.id.equals(questionGroupId))
  }

  def findFormForQuestionGroup(sectionId: String, questionGroupId: String, claim: Claim) = {
    findQuestionGroupForSection(sectionId, questionGroupId, claim).get
  }*/

  def answeredFormsForSection(sectionID: String) = sections.get(sectionID) match {
    case Some(s: Section) => s.forms.filter(form => form.section == sectionID)
    case _ => Nil
  }

  def update(form: CarersAllowanceForm): Claim = {
    val section = sections.get(form.section) match {
      case None => Section(form.section, List(form))
      case Some(s) => Section(form.section, s.forms.filterNot(_.id == form.id) :+ form  )
    }

    Claim(sections.updated(section.id, section))
  }
}

trait CachedClaim {
  import play.api.Play.current

  implicit def unexpectedToLeft(result: Result) = Left(result)

  implicit def expectedToRight(claimingResult: (Claim, Result))  = Right(claimingResult._1, claimingResult._2)

  def newClaim(f: => Claim => Request[AnyContent] => Result) = Action {
    implicit request => {
      val key = request.session.get("connected").getOrElse(java.util.UUID.randomUUID().toString)
      val expiration: Int = 3600
      val claim = Claim()
      Cache.set(key, claim, expiration)
      f(claim)(request).withSession("connected" -> key)
    }
  }<commit_msg>Better naming.<commit_after>package models

import play.api.cache.Cache
import play.api.mvc.{Action, Result, AnyContent, Request}

case class Claim(sections: Map[String, Section] = Map()) extends CreationTimeStamp {

  def section(sectionId: String): Option[Section] = {
    sections.get(sectionId)
  }

  /*def getNextIncompleteSection: Option[Section] = {
    sections.find(section => !section.isComplete)
  }

  def findSectionForClaim(sectionId: String, claim: Claim) = {
    claim.sections.find(section => section.id.equals(sectionId))
  }

  def findQuestionGroupForSection(sectionId: String, questionGroupId: String, claim: Claim) = {
    val sectionOption = findSectionForClaim(sectionId, claim)
    sectionOption.get.forms.find(questionGroup => questionGroup.id.equals(questionGroupId))
  }

  def findFormForQuestionGroup(sectionId: String, questionGroupId: String, claim: Claim) = {
    findQuestionGroupForSection(sectionId, questionGroupId, claim).get
  }*/

  def answeredFormsForSection(sectionID: String) = sections.get(sectionID) match {
    case Some(s: Section) => s.forms.filter(form => form.section == sectionID)
    case _ => Nil
  }

  def update(form: CarersAllowanceForm): Claim = {
    val section = sections.get(form.section) match {
      case None => Section(form.section, List(form))
      case Some(s) => Section(form.section, s.forms.filterNot(_.id == form.id) :+ form  )
    }

    Claim(sections.updated(section.id, section))
  }
}

trait CachedClaim {
  import play.api.Play.current

  implicit def defaultResultToLeft(result: Result) = Left(result)

  implicit def claimAndResultToRight(claimingResult: (Claim, Result)) = Right(claimingResult._1, claimingResult._2)

  def newClaim(f: => Claim => Request[AnyContent] => Result) = Action {
    implicit request => {
      val key = request.session.get("connected").getOrElse(java.util.UUID.randomUUID().toString)
      val expiration: Int = 3600
      val claim = Claim()
      Cache.set(key, claim, expiration)
      f(claim)(request).withSession("connected" -> key)
    }
  }
{'fraction_non_alphanumeric': 0.12709599027946536, 'fraction_numerical': 0.0029161603888213854, 'mean_word_length': 4.359375, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2233627', 'n_tokens_mistral': 1284, 'n_tokens_neox': 1234, 'n_words': 259}