<commit_before>import {Injectable} from '@angular/core';
import {MspApplication, Person} from '../model/application.model';
import {MspAccountApp} from '../model/account.model';
import PersonDto from '../model/person.dto';
import {FinancialAssistApplication} from '../model/financial-assist-application.model';
import {LocalStorageService} from 'angular-2-local-storage';
import FinancialAssistApplicationDto from '../model/financial-assist-application.dto';
import MspApplicationDto from '../model/application.dto';
import MspAccountDto from '../model/account.dto';
import AddressDto from '../model/address.dto';
import {OutofBCRecordDto} from '../model/outof-bc-record.dto';
import {OutofBCRecord} from '../model/outof-bc-record.model';
import {StatusInCanada, Relationship} from '../model/status-activities-documents';
import {puts} from "util";
import {Process} from "./process.service";
import {MspProgressBarItem} from '../common/progressBar/progressBarDataItem.model';
import {Gender} from "../model/person.model";
import {Address} from "../model/address.model";

@Injectable()
export  class MspDataService {
    private _mspApplication: MspApplication;
    private _finAssistApp: FinancialAssistApplication;
    private _mspAccountApp: MspAccountApp;
    private finAssistAppStorageKey: string = 'financial-assist';
    // private finAssistMailingAddressStorageKey:string = 'financial-assist-mailing-address';
    private mspAppStorageKey: string = 'msp-application';
    private mspProcessKey: string = 'msp-process';
    private mspProgressBarKey: string = 'msp-progressbar';  //Progress bar has to be saved since its dynamic .Storing to avoid extra calls in all the getter invocations

    private mspAccountStorageKey: string = 'msp-account';
    private mspAccountKey: string = 'account-process';
    private mspAccountNavBarKey: string = 'account-navbar';

    constructor(private localStorageService: LocalStorageService) {
        this._finAssistApp = this.fetchFinAssistApplication();
        this._mspApplication = this.fetchMspApplication();
        this._mspAccountApp = this.fetchMspAccountApplication();
    }

    destroyAll() {
        this.localStorageService.clearAll();
    }

    getMspProcess(): Process {
        return this.localStorageService.get<Process>(this.mspProcessKey);
    }

    setMspProcess(process: Process) {
        this.localStorageService.set(this.mspProcessKey, process);
    }


    getMspProgressBar (): Array<MspProgressBarItem> {
        return this.localStorageService.get<Array<MspProgressBarItem>>(this.mspProgressBarKey);
    }

    seMspProgressBar(progressBar: Array<MspProgressBarItem>) {
        this.localStorageService.set(this.mspProgressBarKey, progressBar);
    }

    emptyMspProgressBar() {
        this.localStorageService.remove(this.mspProgressBarKey);
    }

    getMspApplication(): MspApplication {
        return this._mspApplication;
    }

    getMspAccountApp(): MspAccountApp {
        return this._mspAccountApp;
    }

    get finAssistApp(): FinancialAssistApplication {
        return this._finAssistApp;
    }

    // return the application or assistance uuid
    getMspUuid(): string {
        let uuid = "";
        if (this._mspApplication)
            uuid = this._mspApplication.uuid;
        else if (this._finAssistApp)
            uuid = this._finAssistApp.uuid;
        return uuid;
    }

    saveMspAccountApp(): void {
        let dto: MspAccountDto = this.toMspAccountAppTransferObject(this._mspAccountApp);
        // console.log('saving msp app: ', dto);
        this.localStorageService.set(this.mspAccountKey, dto);
    }


    saveMspApplication(): void {
        let dto: MspApplicationDto = this.toMspApplicationTransferObject(this._mspApplication);
        // console.log('saving msp app: ', dto);
        this.localStorageService.set(this.mspAppStorageKey, dto);
    }

    private fetchMspApplication(): MspApplication {
        let dto: MspApplicationDto =
            this.localStorageService.get<MspApplicationDto>(this.mspAppStorageKey);

        if (dto) {
            // console.log('MspApplicationDto from local storage: ', dto);
            return this.fromMspApplicationTransferObject(dto);
        } else {
            return new MspApplication();
        }
    }

    private fetchMspAccountApplication(): MspAccountApp {
        let dto: MspAccountDto =
            this.localStorageService.get<MspAccountDto>(this.mspAccountStorageKey);

        if (dto) {
            // console.log('MspApplicationDto from local storage: ', dto);
            return this.fromMspAccountTransferObject(dto);
        } else {
            return new MspAccountApp();
        }
    }

    saveFinAssistApplication(): void {
        // console.log('this._finAssistApp before conversion and saving: ');
        // console.log(this._finAssistApp);
        let dto: FinancialAssistApplicationDto = this.toFinAssistDataTransferObject(this._finAssistApp);
        this.localStorageService.set(this.finAssistAppStorageKey, dto);
        // this.localStorageService.set(this.finAssistMailingAddressStorageKey,dto.mailingAddress);
    }

    private fetchFinAssistApplication(): FinancialAssistApplication {
        let dto: FinancialAssistApplicationDto =
            this.localStorageService.get<FinancialAssistApplicationDto>(this.finAssistAppStorageKey);

        // let mailAddressDto:AddressDto =
        //   this.localStorageService.get<AddressDto>(this.finAssistMailingAddressStorageKey);

        if (dto) {
            // dto.mailingAddress = mailAddressDto;
            return this.fromFinAssistDataTransferObject(dto);
        } else {
            return new FinancialAssistApplication();
        }
    }

    public getFakeAccountChangeApplication(): MspAccountApp {
       let mspAccountApp:MspAccountApp = this._mspAccountApp;
        mspAccountApp.applicant.firstName = "NA";
        mspAccountApp.applicant.lastName = "NA";
        mspAccountApp.applicant.gender = Gender.Male;
        mspAccountApp.applicant.dob_day = 1;
        mspAccountApp.applicant.dob_month = 1;
        mspAccountApp.applicant.dob_year = 2000;
        mspAccountApp.applicant.previous_phn = "1234567890";
        mspAccountApp.phoneNumber = "2501234567";
        let dumyAddress: Address = new Address();
        dumyAddress.addressLine1 = "NA";
        mspAccountApp.authorizedByApplicant = true;<commit_msg>flag added for the fake application<commit_after>import {Injectable} from '@angular/core';
import {MspApplication, Person} from '../model/application.model';
import {MspAccountApp} from '../model/account.model';
import PersonDto from '../model/person.dto';
import {FinancialAssistApplication} from '../model/financial-assist-application.model';
import {LocalStorageService} from 'angular-2-local-storage';
import FinancialAssistApplicationDto from '../model/financial-assist-application.dto';
import MspApplicationDto from '../model/application.dto';
import MspAccountDto from '../model/account.dto';
import AddressDto from '../model/address.dto';
import {OutofBCRecordDto} from '../model/outof-bc-record.dto';
import {OutofBCRecord} from '../model/outof-bc-record.model';
import {StatusInCanada, Relationship} from '../model/status-activities-documents';
import {puts} from "util";
import {Process} from "./process.service";
import {MspProgressBarItem} from '../common/progressBar/progressBarDataItem.model';
import {Gender} from "../model/person.model";
import {Address} from "../model/address.model";

@Injectable()
export  class MspDataService {
    private _mspApplication: MspApplication;
    private _finAssistApp: FinancialAssistApplication;
    private _mspAccountApp: MspAccountApp;
    private finAssistAppStorageKey: string = 'financial-assist';
    // private finAssistMailingAddressStorageKey:string = 'financial-assist-mailing-address';
    private mspAppStorageKey: string = 'msp-application';
    private mspProcessKey: string = 'msp-process';
    private mspProgressBarKey: string = 'msp-progressbar';  //Progress bar has to be saved since its dynamic .Storing to avoid extra calls in all the getter invocations

    private mspAccountStorageKey: string = 'msp-account';
    private mspAccountKey: string = 'account-process';
    private mspAccountNavBarKey: string = 'account-navbar';

    constructor(private localStorageService: LocalStorageService) {
        this._finAssistApp = this.fetchFinAssistApplication();
        this._mspApplication = this.fetchMspApplication();
        this._mspAccountApp = this.fetchMspAccountApplication();
    }

    destroyAll() {
        this.localStorageService.clearAll();
    }

    getMspProcess(): Process {
        return this.localStorageService.get<Process>(this.mspProcessKey);
    }

    setMspProcess(process: Process) {
        this.localStorageService.set(this.mspProcessKey, process);
    }


    getMspProgressBar (): Array<MspProgressBarItem> {
        return this.localStorageService.get<Array<MspProgressBarItem>>(this.mspProgressBarKey);
    }

    seMspProgressBar(progressBar: Array<MspProgressBarItem>) {
        this.localStorageService.set(this.mspProgressBarKey, progressBar);
    }

    emptyMspProgressBar() {
        this.localStorageService.remove(this.mspProgressBarKey);
    }

    getMspApplication(): MspApplication {
        return this._mspApplication;
    }

    getMspAccountApp(): MspAccountApp {
        return this._mspAccountApp;
    }

    get finAssistApp(): FinancialAssistApplication {
        return this._finAssistApp;
    }

    // return the application or assistance uuid
    getMspUuid(): string {
        let uuid = "";
        if (this._mspApplication)
            uuid = this._mspApplication.uuid;
        else if (this._finAssistApp)
            uuid = this._finAssistApp.uuid;
        return uuid;
    }

    saveMspAccountApp(): void {
        let dto: MspAccountDto = this.toMspAccountAppTransferObject(this._mspAccountApp);
        // console.log('saving msp app: ', dto);
        this.localStorageService.set(this.mspAccountKey, dto);
    }


    saveMspApplication(): void {
        let dto: MspApplicationDto = this.toMspApplicationTransferObject(this._mspApplication);
        // console.log('saving msp app: ', dto);
        this.localStorageService.set(this.mspAppStorageKey, dto);
    }

    private fetchMspApplication(): MspApplication {
        let dto: MspApplicationDto =
            this.localStorageService.get<MspApplicationDto>(this.mspAppStorageKey);

        if (dto) {
            // console.log('MspApplicationDto from local storage: ', dto);
            return this.fromMspApplicationTransferObject(dto);
        } else {
            return new MspApplication();
        }
    }

    private fetchMspAccountApplication(): MspAccountApp {
        let dto: MspAccountDto =
            this.localStorageService.get<MspAccountDto>(this.mspAccountStorageKey);

        if (dto) {
            // console.log('MspApplicationDto from local storage: ', dto);
            return this.fromMspAccountTransferObject(dto);
        } else {
            return new MspAccountApp();
        }
    }

    saveFinAssistApplication(): void {
        // console.log('this._finAssistApp before conversion and saving: ');
        // console.log(this._finAssistApp);
        let dto: FinancialAssistApplicationDto = this.toFinAssistDataTransferObject(this._finAssistApp);
        this.localStorageService.set(this.finAssistAppStorageKey, dto);
        // this.localStorageService.set(this.finAssistMailingAddressStorageKey,dto.mailingAddress);
    }

    private fetchFinAssistApplication(): FinancialAssistApplication {
        let dto: FinancialAssistApplicationDto =
            this.localStorageService.get<FinancialAssistApplicationDto>(this.finAssistAppStorageKey);

        // let mailAddressDto:AddressDto =
        //   this.localStorageService.get<AddressDto>(this.finAssistMailingAddressStorageKey);

        if (dto) {
            // dto.mailingAddress = mailAddressDto;
            return this.fromFinAssistDataTransferObject(dto);
        } else {
            return new FinancialAssistApplication();
        }
    }

    public getFakeAccountChangeApplication(): MspAccountApp {
       let mspAccountApp:MspAccountApp = this._mspAccountApp;
        mspAccountApp.accountChangeOptions.addressUpdate = true;
        mspAccountApp.applicant.firstName = "NA";
        mspAccountApp.applicant.lastName = "NA";
        mspAccountApp.applicant.gender = Gender.Male;
        mspAccountApp.applicant.dob_day = 1;
        mspAccountApp.applicant.dob_month = 1;
        mspAccountApp.applicant.dob_year = 2000;
        mspAccountApp.applicant.previous_phn = "1234567890";
        mspAccountApp.phoneNumber = "2501234567";
        let dumyAddress: Address = new Address();
        dumyAddress.addressLine1 = "NA";
        mspAccountApp.authorizedByApplicant = true;
{'fraction_non_alphanumeric': 0.10455993163986639, 'fraction_numerical': 0.004350190320826536, 'mean_word_length': 3.389362427548585, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '6074678', 'n_tokens_mistral': 3772, 'n_tokens_neox': 3700, 'n_words': 666}