<commit_before>/*
 * Copyright 2017 HM Revenue & Customs
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package iht.controllers.registration.deceased

import iht.connector.{CachingConnector, IhtConnectors}
import iht.controllers.ControllerHelper.Mode
import iht.controllers.registration.{RegistrationController, routes => registrationRoutes}
import iht.forms.registration.DeceasedForms
import iht.forms.registration.DeceasedForms.aboutDeceasedForm
import iht.metrics.Metrics
import iht.models.{DeceasedDetails, RegistrationDetails}
import iht.utils.CommonHelper
import iht.views.html.registration.{deceased => views}
import org.joda.time.LocalDate
import play.api.Play.current
import play.api.data.Form
import play.api.i18n.Messages.Implicits._
import play.api.mvc._

import scala.concurrent.Future

object AboutDeceasedController extends AboutDeceasedController with IhtConnectors {
  def metrics: Metrics = Metrics
  override def deceasedForms = DeceasedForms
}

trait AboutDeceasedController extends RegistrationController {
  def cachingConnector: CachingConnector
  def deceasedForms: DeceasedForms

  override def guardConditions = guardConditionsAboutDeceased

  def onPageLoad = pageLoad(routes.AboutDeceasedController.onSubmit())

  def onEditPageLoad = pageLoad(routes.AboutDeceasedController.onEditSubmit(), Mode.Edit, cancelToRegSummary)

  def pageLoad(actionCall: Call, mode: Mode.Value = Mode.Standard,
               cancelCall: Option[Call] = None) = authorisedForIht {
    implicit user =>
      implicit request =>
        withRegistrationDetailsRedirectOnGuardCondition { rd =>
          val deceasedName = CommonHelper.getDeceasedNameOrDefaultString(rd)
          val dateOfDeath = rd.deceasedDateOfDeath.map(_.dateOfDeath).getOrElse(LocalDate.now)
          val f = rd.deceasedDetails.fold(aboutDeceasedForm())(dd => aboutDeceasedForm(dateOfDeath).fill(dd))
          val okResult: Result = if (mode == Mode.Standard) {
            okForPageLoad(f, Some(deceasedName))
          } else {
            okForEditPageLoad(f, Some(deceasedName))
          }
          val result = okResult.withSession(CommonHelper.ensureSessionHasNino(request.session, user))
          Future.successful(result)<commit_msg>IHT-4761 Code lost due to merge<commit_after>/*
 * Copyright 2017 HM Revenue & Customs
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package iht.controllers.registration.deceased

import iht.connector.{CachingConnector, IhtConnectors}
import iht.controllers.ControllerHelper.Mode
import iht.controllers.registration.{RegistrationController, routes => registrationRoutes}
import iht.forms.registration.DeceasedForms
import iht.forms.registration.DeceasedForms.aboutDeceasedForm
import iht.metrics.Metrics
import iht.models.{DeceasedDetails, RegistrationDetails}
import iht.utils.{DeceasedInfoHelper, SessionHelper}
import iht.views.html.registration.{deceased => views}
import org.joda.time.LocalDate
import play.api.Play.current
import play.api.data.Form
import play.api.i18n.Messages.Implicits._
import play.api.mvc._

import scala.concurrent.Future

object AboutDeceasedController extends AboutDeceasedController with IhtConnectors {
  def metrics: Metrics = Metrics
  override def deceasedForms = DeceasedForms
}

trait AboutDeceasedController extends RegistrationController {
  def cachingConnector: CachingConnector
  def deceasedForms: DeceasedForms

  override def guardConditions = guardConditionsAboutDeceased

  def onPageLoad = pageLoad(routes.AboutDeceasedController.onSubmit())

  def onEditPageLoad = pageLoad(routes.AboutDeceasedController.onEditSubmit(), Mode.Edit, cancelToRegSummary)

  def pageLoad(actionCall: Call, mode: Mode.Value = Mode.Standard,
               cancelCall: Option[Call] = None) = authorisedForIht {
    implicit user =>
      implicit request =>
        withRegistrationDetailsRedirectOnGuardCondition { rd =>
          val deceasedName = DeceasedInfoHelper.getDeceasedNameOrDefaultString(rd)
          val dateOfDeath = rd.deceasedDateOfDeath.map(_.dateOfDeath).getOrElse(LocalDate.now)
          val f = rd.deceasedDetails.fold(aboutDeceasedForm())(dd => aboutDeceasedForm(dateOfDeath).fill(dd))
          val okResult: Result = if (mode == Mode.Standard) {
            okForPageLoad(f, Some(deceasedName))
          } else {
            okForEditPageLoad(f, Some(deceasedName))
          }
          val result = okResult.withSession(SessionHelper.ensureSessionHasNino(request.session, user))
          Future.successful(result)
{'fraction_non_alphanumeric': 0.07959479015918958, 'fraction_numerical': 0.004341534008683068, 'mean_word_length': 4.441929133858268, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6203997', 'n_tokens_mistral': 1577, 'n_tokens_neox': 1527, 'n_words': 403}