<commit_before>package controllers

import audit1._
import com.google.inject.Inject
import models._
import play.api.data.Form
import play.api.data.FormError
import play.api.mvc.Result
import play.api.mvc._
import uk.gov.dvla.vehicles.presentation.common.clientsidesession.CookieImplicits.RichCookies
import uk.gov.dvla.vehicles.presentation.common.clientsidesession.CookieImplicits.RichResult
import uk.gov.dvla.vehicles.presentation.common.clientsidesession.ClearTextClientSideSessionFactory
import uk.gov.dvla.vehicles.presentation.common.clientsidesession.ClientSideSessionFactory
import uk.gov.dvla.vehicles.presentation.common.clientsidesession.CookieKeyValue
import uk.gov.dvla.vehicles.presentation.common.model.VehicleAndKeeperDetailsModel
import uk.gov.dvla.vehicles.presentation.common.services.DateService
import uk.gov.dvla.vehicles.presentation.common.views.helpers.FormExtensions._
import utils.helpers.Config
import views.vrm_assign.Confirm._
import views.vrm_assign.RelatedCacheKeys.removeCookiesOnExit
import views.vrm_assign.VehicleLookup._
import views.vrm_assign.Confirm.SupplyEmailId
import views.vrm_assign.Confirm.SupplyEmail_true
import webserviceclients.audit2
import webserviceclients.audit2.AuditRequest

final class Confirm @Inject()(
                               auditService1: audit1.AuditService,
                               auditService2: audit2.AuditService,
                               dateService: DateService
                               )
                             (implicit clientSideSessionFactory: ClientSideSessionFactory,
                              config: Config) extends Controller {

  private[controllers] val form = Form(ConfirmFormModel.Form.Mapping)

  def present = Action { implicit request =>
    (request.cookies.getModel[VehicleAndKeeperLookupFormModel],
      request.cookies.getModel[VehicleAndKeeperDetailsModel],
      request.cookies.getModel[CaptureCertificateDetailsFormModel],
      request.cookies.getModel[CaptureCertificateDetailsModel],
      request.cookies.getModel[FulfilModel]) match {
      case (Some(vehicleAndKeeperLookupForm), Some(vehicleAndKeeper),
      Some(captureCertDetailsForm), Some(captureCertDetails), None) =>
        val viewModel = ConfirmViewModel(vehicleAndKeeper, captureCertDetailsForm,
          captureCertDetails.outstandingDates, captureCertDetails.outstandingFees, vehicleAndKeeperLookupForm.userType)
        val emptyForm = form // Always fill the form with empty values to force user to enter new details. Also helps
      // with the situation where payment fails and they come back to this page via either back button or coming
      // forward from vehicle lookup - this could now be a different customer! We don't want the chance that one
      // customer gives up and then a new customer starts the journey in the same session and the email field is
      // pre-populated with the previous customer's address.
      val isKeeperEmailDisplayedOnLoad = false // Due to the form always being empty, the keeper email field will
      // always be hidden on first load
      val isKeeper = vehicleAndKeeperLookupForm.userType == UserType_Keeper
        Ok(views.html.vrm_assign.confirm(viewModel, emptyForm, isKeeperEmailDisplayedOnLoad, isKeeper))
      case _ =>
        Redirect(routes.CaptureCertificateDetails.present())
    }
  }

  def submit = Action { implicit request =>
    form.bindFromRequest.fold(
      invalidForm => handleInvalid(invalidForm),
      model => handleValid(model)
    )
  }

  private def formWithReplacedErrors(form: Form[ConfirmFormModel], id: String, msgId: String) =
    form.
      replaceError(
        KeeperEmailId,
        FormError(
          key = id,
          message = msgId,<commit_msg>Tidy up Confirm controller<commit_after>package controllers

import audit1._
import com.google.inject.Inject
import models._
import play.api.data.Form
import play.api.data.FormError
import play.api.mvc.Result
import play.api.mvc._
import uk.gov.dvla.vehicles.presentation.common.clientsidesession.ClearTextClientSideSessionFactory
import uk.gov.dvla.vehicles.presentation.common.clientsidesession.ClientSideSessionFactory
import uk.gov.dvla.vehicles.presentation.common.clientsidesession.CookieImplicits.RichCookies
import uk.gov.dvla.vehicles.presentation.common.clientsidesession.CookieImplicits.RichResult
import uk.gov.dvla.vehicles.presentation.common.clientsidesession.CookieKeyValue
import uk.gov.dvla.vehicles.presentation.common.model.VehicleAndKeeperDetailsModel
import uk.gov.dvla.vehicles.presentation.common.services.DateService
import uk.gov.dvla.vehicles.presentation.common.views.helpers.FormExtensions._
import utils.helpers.Config
import views.vrm_assign.Confirm.SupplyEmailId
import views.vrm_assign.Confirm.SupplyEmail_true
import views.vrm_assign.Confirm._
import views.vrm_assign.RelatedCacheKeys.removeCookiesOnExit
import views.vrm_assign.VehicleLookup._
import webserviceclients.audit2
import webserviceclients.audit2.AuditRequest

final class Confirm @Inject()(
                               auditService1: audit1.AuditService,
                               auditService2: audit2.AuditService,
                               dateService: DateService
                               )
                             (implicit clientSideSessionFactory: ClientSideSessionFactory,
                              config: Config) extends Controller {

  private[controllers] val form = Form(ConfirmFormModel.Form.Mapping)

  def present = Action { implicit request =>
    (request.cookies.getModel[VehicleAndKeeperLookupFormModel],
      request.cookies.getModel[VehicleAndKeeperDetailsModel],
      request.cookies.getModel[CaptureCertificateDetailsFormModel],
      request.cookies.getModel[CaptureCertificateDetailsModel],
      request.cookies.getModel[FulfilModel]) match {
      case (Some(vehicleAndKeeperLookupForm), Some(vehicleAndKeeper),
      Some(captureCertDetailsForm), Some(captureCertDetails), None) =>
        val viewModel = ConfirmViewModel(vehicleAndKeeper, captureCertDetailsForm,
          captureCertDetails.outstandingDates, captureCertDetails.outstandingFees, vehicleAndKeeperLookupForm.userType)
        val emptyForm = form // Always fill the form with empty values to force user to enter new details. Also helps
        // with the situation where payment fails and they come back to this page via either back button or coming
        // forward from vehicle lookup - this could now be a different customer! We don't want the chance that one
        // customer gives up and then a new customer starts the journey in the same session and the email field is
        // pre-populated with the previous customer's address.
        val isKeeperEmailDisplayedOnLoad = false // Due to the form always being empty, the keeper email field will
        // always be hidden on first load
        val isKeeper = vehicleAndKeeperLookupForm.userType == UserType_Keeper
        Ok(views.html.vrm_assign.confirm(viewModel, emptyForm, isKeeperEmailDisplayedOnLoad, isKeeper))
      case _ =>
        Redirect(routes.CaptureCertificateDetails.present())
    }
  }

  def submit = Action { implicit request =>
    form.bindFromRequest.fold(
      invalidForm => handleInvalid(invalidForm),
      model => handleValid(model)
    )
  }

  private def formWithReplacedErrors(form: Form[ConfirmFormModel], id: String, msgId: String) =
    form.
      replaceError(
        KeeperEmailId,
        FormError(
          key = id,
          message = msgId,
{'fraction_non_alphanumeric': 0.07066011422499668, 'fraction_numerical': 0.0018594766901314915, 'mean_word_length': 3.608323133414933, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '2335279', 'n_tokens_mistral': 2050, 'n_tokens_neox': 1995, 'n_words': 466}