<commit_before>/*
 * Copyright 2018 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 models.businessactivities

import config.ApplicationConfig
import models.registrationprogress.{Completed, NotStarted, Section, Started}
import uk.gov.hmrc.http.cache.client.CacheMap
import models.businessactivities.TransactionTypes._
import models.businessmatching.{AccountancyServices, BusinessMatching, BusinessActivities => ba}
import utils.ControllerHelper

case class BusinessActivities(
                               involvedInOther: Option[InvolvedInOther] = None,
                               expectedBusinessTurnover: Option[ExpectedBusinessTurnover] = None,
                               expectedAMLSTurnover: Option[ExpectedAMLSTurnover] = None,
                               businessFranchise: Option[BusinessFranchise] = None,
                               transactionRecord: Option[Boolean] = None,
                               customersOutsideUK: Option[CustomersOutsideUK] = None,
                               ncaRegistered: Option[NCARegistered] = None,
                               accountantForAMLSRegulations: Option[AccountantForAMLSRegulations] = None,
                               identifySuspiciousActivity: Option[IdentifySuspiciousActivity] = None,
                               riskAssessmentPolicy: Option[RiskAssessmentPolicy] = None,
                               howManyEmployees: Option[HowManyEmployees] = None,
                               whoIsYourAccountant: Option[WhoIsYourAccountant] = None,
                               taxMatters: Option[TaxMatters] = None,
                               transactionRecordTypes: Option[TransactionTypes] = None,
                               hasChanged: Boolean = false,
                               hasAccepted: Boolean = false
                             ) {

  def businessFranchise(p: BusinessFranchise): BusinessActivities =
    this.copy(businessFranchise = Some(p), hasChanged = hasChanged || !this.businessFranchise.contains(p),
      hasAccepted = hasAccepted && this.businessFranchise.contains(p))

  def expectedAMLSTurnover(p: ExpectedAMLSTurnover): BusinessActivities =
    this.copy(expectedAMLSTurnover = Some(p), hasChanged = hasChanged || !this.expectedAMLSTurnover.contains(p),
      hasAccepted = hasAccepted && this.expectedAMLSTurnover.contains(p))

  def expectedBusinessTurnover(p: ExpectedBusinessTurnover): BusinessActivities =
    this.copy(expectedBusinessTurnover = Some(p), hasChanged = hasChanged || !this.expectedBusinessTurnover.contains(p),
      hasAccepted = hasAccepted && this.expectedBusinessTurnover.contains(p))

  def involvedInOther(p: InvolvedInOther): BusinessActivities =
    this.copy(involvedInOther = Some(p), hasChanged = hasChanged || !this.involvedInOther.contains(p),
      hasAccepted = hasAccepted && this.involvedInOther.contains(p))

  def identifySuspiciousActivity(p: IdentifySuspiciousActivity): BusinessActivities =
    this.copy(identifySuspiciousActivity = Some(p), hasChanged = hasChanged || !this.identifySuspiciousActivity.contains(p),
      hasAccepted = hasAccepted && this.identifySuspiciousActivity.contains(p))

  def transactionRecord(isRecorded: Boolean): BusinessActivities = {
    val types = if (isRecorded) this.transactionRecordTypes else None

    this.copy(transactionRecord = Some(isRecorded), transactionRecordTypes = types,
      hasChanged = hasChanged || !this.transactionRecord.contains(isRecorded),
      hasAccepted = hasAccepted && this.transactionRecord.contains(isRecorded))
  }

  def transactionRecordTypes(types: TransactionTypes): BusinessActivities =
    this.copy(transactionRecordTypes = Some(types), hasChanged = hasChanged || !this.transactionRecordTypes.contains(types),
      hasAccepted = hasAccepted && this.transactionRecordTypes.contains(types))

  def customersOutsideUK(p: CustomersOutsideUK): BusinessActivities =
    this.copy(customersOutsideUK = Some(p), hasChanged = hasChanged || !this.customersOutsideUK.contains(p),
      hasAccepted = hasAccepted && this.customersOutsideUK.contains(p))

  def ncaRegistered(p: NCARegistered): BusinessActivities =
    this.copy(ncaRegistered = Some(p), hasChanged = hasChanged || !this.ncaRegistered.contains(p),
      hasAccepted = hasAccepted && this.ncaRegistered.contains(p))

  def accountantForAMLSRegulations(p: Option[AccountantForAMLSRegulations]): BusinessActivities =
    this.copy(accountantForAMLSRegulations = p, hasChanged = hasChanged || !this.accountantForAMLSRegulations.equals(p),
      hasAccepted = hasAccepted && this.accountantForAMLSRegulations.equals(p))

  def riskAssessmentPolicy(p: RiskAssessmentPolicy): BusinessActivities =
    this.copy(riskAssessmentPolicy = Some(p), hasChanged = hasChanged || !this.riskAssessmentPolicy.contains(p),
      hasAccepted = hasAccepted && this.riskAssessmentPolicy.contains(p))

  def howManyEmployees(p: HowManyEmployees): BusinessActivities =
    this.copy(howManyEmployees = Some(p), hasChanged = hasChanged || !this.howManyEmployees.contains(p),
      hasAccepted = hasAccepted && this.howManyEmployees.contains(p))

  def whoIsYourAccountant(p: Option[WhoIsYourAccountant]): BusinessActivities =
    this.copy(whoIsYourAccountant = p, hasChanged = hasChanged || !this.whoIsYourAccountant.equals(p),
      hasAccepted = hasAccepted && this.whoIsYourAccountant.equals(p))

  def taxMatters(p: TaxMatters): BusinessActivities =
    this.copy(taxMatters = Some(p), hasChanged = hasChanged || !this.taxMatters.contains(p),
      hasAccepted = hasAccepted && this.taxMatters.contains(p))


  def isComplete(bmBusinessActivities : Option[ba]): Boolean = {

    val containsASP = bmBusinessActivities.fold(false) { x =>
      x.businessActivities contains AccountancyServices
    }

    if (ApplicationConfig.hasAcceptedToggle) {
      this match {
        case BusinessActivities(
        Some(_), _, Some(_), Some(_), Some(_), _,
        Some(_), Some(_), Some(_), Some(_), Some(_), _, _, _, _, true) if !containsASP => true
        case BusinessActivities(
        Some(_), _, Some(_), Some(_), Some(_), _,
        Some(_), None, Some(_), Some(_), Some(_), _, _, _, _, true) if containsASP => true
        case BusinessActivities(
        Some(_), _, Some(_), Some(_), Some(_), _,
        Some(_), _, Some(_), Some(_), Some(_), _, _, _, _, false) => false
        case _ => false
      }
  } else {
      this match {
        case BusinessActivities(
        Some(_), _, Some(_), Some(_), Some(_), _,
        Some(_), Some(_), Some(_), Some(_), Some(_), _, _, _, _, _) if !containsASP => true
        case BusinessActivities(
        Some(_), _, Some(_), Some(_), Some(_), _,
        Some(_), None, Some(_), Some(_), Some(_), _, _, _, _, _) if containsASP => true
        case _ => false
      }
    }<commit_msg>AMLS-3057 fis iscomplete logic<commit_after>/*
 * Copyright 2018 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 models.businessactivities

import config.ApplicationConfig
import models.registrationprogress.{Completed, NotStarted, Section, Started}
import uk.gov.hmrc.http.cache.client.CacheMap
import models.businessactivities.TransactionTypes._
import models.businessmatching.{AccountancyServices, BusinessMatching, BusinessActivities => ba}
import utils.ControllerHelper

case class BusinessActivities(
                               involvedInOther: Option[InvolvedInOther] = None,
                               expectedBusinessTurnover: Option[ExpectedBusinessTurnover] = None,
                               expectedAMLSTurnover: Option[ExpectedAMLSTurnover] = None,
                               businessFranchise: Option[BusinessFranchise] = None,
                               transactionRecord: Option[Boolean] = None,
                               customersOutsideUK: Option[CustomersOutsideUK] = None,
                               ncaRegistered: Option[NCARegistered] = None,
                               accountantForAMLSRegulations: Option[AccountantForAMLSRegulations] = None,
                               identifySuspiciousActivity: Option[IdentifySuspiciousActivity] = None,
                               riskAssessmentPolicy: Option[RiskAssessmentPolicy] = None,
                               howManyEmployees: Option[HowManyEmployees] = None,
                               whoIsYourAccountant: Option[WhoIsYourAccountant] = None,
                               taxMatters: Option[TaxMatters] = None,
                               transactionRecordTypes: Option[TransactionTypes] = None,
                               hasChanged: Boolean = false,
                               hasAccepted: Boolean = false
                             ) {

  def businessFranchise(p: BusinessFranchise): BusinessActivities =
    this.copy(businessFranchise = Some(p), hasChanged = hasChanged || !this.businessFranchise.contains(p),
      hasAccepted = hasAccepted && this.businessFranchise.contains(p))

  def expectedAMLSTurnover(p: ExpectedAMLSTurnover): BusinessActivities =
    this.copy(expectedAMLSTurnover = Some(p), hasChanged = hasChanged || !this.expectedAMLSTurnover.contains(p),
      hasAccepted = hasAccepted && this.expectedAMLSTurnover.contains(p))

  def expectedBusinessTurnover(p: ExpectedBusinessTurnover): BusinessActivities =
    this.copy(expectedBusinessTurnover = Some(p), hasChanged = hasChanged || !this.expectedBusinessTurnover.contains(p),
      hasAccepted = hasAccepted && this.expectedBusinessTurnover.contains(p))

  def involvedInOther(p: InvolvedInOther): BusinessActivities =
    this.copy(involvedInOther = Some(p), hasChanged = hasChanged || !this.involvedInOther.contains(p),
      hasAccepted = hasAccepted && this.involvedInOther.contains(p))

  def identifySuspiciousActivity(p: IdentifySuspiciousActivity): BusinessActivities =
    this.copy(identifySuspiciousActivity = Some(p), hasChanged = hasChanged || !this.identifySuspiciousActivity.contains(p),
      hasAccepted = hasAccepted && this.identifySuspiciousActivity.contains(p))

  def transactionRecord(isRecorded: Boolean): BusinessActivities = {
    val types = if (isRecorded) this.transactionRecordTypes else None

    this.copy(transactionRecord = Some(isRecorded), transactionRecordTypes = types,
      hasChanged = hasChanged || !this.transactionRecord.contains(isRecorded),
      hasAccepted = hasAccepted && this.transactionRecord.contains(isRecorded))
  }

  def transactionRecordTypes(types: TransactionTypes): BusinessActivities =
    this.copy(transactionRecordTypes = Some(types), hasChanged = hasChanged || !this.transactionRecordTypes.contains(types),
      hasAccepted = hasAccepted && this.transactionRecordTypes.contains(types))

  def customersOutsideUK(p: CustomersOutsideUK): BusinessActivities =
    this.copy(customersOutsideUK = Some(p), hasChanged = hasChanged || !this.customersOutsideUK.contains(p),
      hasAccepted = hasAccepted && this.customersOutsideUK.contains(p))

  def ncaRegistered(p: NCARegistered): BusinessActivities =
    this.copy(ncaRegistered = Some(p), hasChanged = hasChanged || !this.ncaRegistered.contains(p),
      hasAccepted = hasAccepted && this.ncaRegistered.contains(p))

  def accountantForAMLSRegulations(p: Option[AccountantForAMLSRegulations]): BusinessActivities =
    this.copy(accountantForAMLSRegulations = p, hasChanged = hasChanged || !this.accountantForAMLSRegulations.equals(p),
      hasAccepted = hasAccepted && this.accountantForAMLSRegulations.equals(p))

  def riskAssessmentPolicy(p: RiskAssessmentPolicy): BusinessActivities =
    this.copy(riskAssessmentPolicy = Some(p), hasChanged = hasChanged || !this.riskAssessmentPolicy.contains(p),
      hasAccepted = hasAccepted && this.riskAssessmentPolicy.contains(p))

  def howManyEmployees(p: HowManyEmployees): BusinessActivities =
    this.copy(howManyEmployees = Some(p), hasChanged = hasChanged || !this.howManyEmployees.contains(p),
      hasAccepted = hasAccepted && this.howManyEmployees.contains(p))

  def whoIsYourAccountant(p: Option[WhoIsYourAccountant]): BusinessActivities =
    this.copy(whoIsYourAccountant = p, hasChanged = hasChanged || !this.whoIsYourAccountant.equals(p),
      hasAccepted = hasAccepted && this.whoIsYourAccountant.equals(p))

  def taxMatters(p: TaxMatters): BusinessActivities =
    this.copy(taxMatters = Some(p), hasChanged = hasChanged || !this.taxMatters.contains(p),
      hasAccepted = hasAccepted && this.taxMatters.contains(p))


  def isComplete(bmBusinessActivities : Option[ba]): Boolean = {

    val containsASP = bmBusinessActivities.fold(false) { x =>
      x.businessActivities contains AccountancyServices
    }

    if (ApplicationConfig.hasAcceptedToggle) {
      this match {
        case BusinessActivities(
        Some(_), _, Some(_), Some(_), Some(_), _,
        Some(_), Some(_), Some(_), Some(_), Some(_), _, _, _, _, true) if !containsASP => true
        case BusinessActivities(
        Some(_), _, Some(_), Some(_), Some(_), _,
        Some(_), _, Some(_), Some(_), Some(_), _, _, _, _, true) if containsASP => true
        case BusinessActivities(
        Some(_), _, Some(_), Some(_), Some(_), _,
        Some(_), _, Some(_), Some(_), Some(_), _, _, _, _, false) => false
        case _ => false
      }
  } else {
      this match {
        case BusinessActivities(
        Some(_), _, Some(_), Some(_), Some(_), _,
        Some(_), Some(_), Some(_), Some(_), Some(_), _, _, _, _, _) if !containsASP => true
        case BusinessActivities(
        Some(_), _, Some(_), Some(_), Some(_), _,
        Some(_), _, Some(_), Some(_), Some(_), _, _, _, _, _) if containsASP => true
        case _ => false
      }
    }
{'fraction_non_alphanumeric': 0.10374346083293702, 'fraction_numerical': 0.0013587879611386643, 'mean_word_length': 3.489173528514791, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '1212796', 'n_tokens_mistral': 4079, 'n_tokens_neox': 3905, 'n_words': 849}