<commit_before>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Mail;
using Alpinely.TownCrier;
using FLS.Common.Extensions;
using FLS.Common.Validators;
using FLS.Data.WebApi.Registrations;
using FLS.Server.Data.DbEntities;
using FLS.Server.Service.Email.Model;
using NLog;

namespace FLS.Server.Service.Email
{
    public class RegistrationEmailBuildService : EmailBuildService
    {
        public RegistrationEmailBuildService(DataAccessService dataAccessService, 
            IEmailSendService emailSendService, TemplateService templateService)
            : base(dataAccessService, emailSendService, templateService)
        {
            
        }
        
        public MailMessage CreateTrialFlightRegistrationEmailForTrialPilot(Person trialPilotPerson, DateTime selectedDate, 
            string emailRecipientAddress, Guid clubId, string locationName)
        {
            trialPilotPerson.ArgumentNotNull("trialPilotPerson");

            var model = new TrialFlightRegistrationModel()
            {
                RecipientName = trialPilotPerson.DisplayName,
                SelectedTrialFlightDate = selectedDate.ToShortDateString(),
                WillBeContactedOnDate = selectedDate.AddDays(-3).ToShortDateString(),
                LocationName = locationName
            };

            var factory = new MergedEmailFactory(new VelocityTemplateParser("TrialFlightRegistrationModel"));

            var tokenValues = new Dictionary<string, object>
                {
                    {"TrialFlightRegistrationModel", model}
                };

            return base.BuildEmail("TrialFlightRegistrationEmailForTrialPilot", factory, tokenValues, emailRecipientAddress.SanitizeEmailAddress(), clubId);
        }

        public MailMessage CreateTrialFlightRegistrationEmailForOrganisator(TrialFlightRegistrationDetails trialFlightRegistrationDetails, string emailRecipientAddress, Guid clubId, string locationName, string reservationInfo)
        {
            trialFlightRegistrationDetails.ArgumentNotNull("trialFlightRegistrationDetails");

            var model = new TrialFlightRegistrationModel()
            {
                Firstname = trialFlightRegistrationDetails.Firstname,
                Lastname = trialFlightRegistrationDetails.Lastname,
                AddressLine1 = trialFlightRegistrationDetails.AddressLine1,
                ZipCode = trialFlightRegistrationDetails.ZipCode,
                City = trialFlightRegistrationDetails.City,
                BusinessPhoneNumber = trialFlightRegistrationDetails.BusinessPhoneNumber,
                MobilePhoneNumber = trialFlightRegistrationDetails.MobilePhoneNumber,
                PrivatePhoneNumber = trialFlightRegistrationDetails.PrivatePhoneNumber,
                PrivateEmail = trialFlightRegistrationDetails.PrivateEmail,
                SelectedTrialFlightDate = trialFlightRegistrationDetails.SelectedDay.ToShortDateString(),
                WillBeContactedOnDate = trialFlightRegistrationDetails.SelectedDay.AddDays(-3).ToShortDateString(),
                LocationName = locationName,
                ReservationInformation = reservationInfo,
                Remarks = trialFlightRegistrationDetails.Remarks
            };

            if (trialFlightRegistrationDetails.InvoiceAddressIsSame)
            {
                model.InvoiceToFirstname = trialFlightRegistrationDetails.Firstname;
                model.InvoiceToLastname = trialFlightRegistrationDetails.Lastname;
                model.InvoiceToAddressLine1 = trialFlightRegistrationDetails.AddressLine1;
                model.InvoiceToZipCode = trialFlightRegistrationDetails.ZipCode;
                model.InvoiceToCity = trialFlightRegistrationDetails.City;
            }
            else
            {
                model.InvoiceToFirstname = trialFlightRegistrationDetails.InvoiceToFirstname;
                model.InvoiceToLastname = trialFlightRegistrationDetails.InvoiceToLastname;
                model.InvoiceToAddressLine1 = trialFlightRegistrationDetails.InvoiceToAddressLine1;<commit_msg>Trial flight pilot will be contacted two days before<commit_after>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Mail;
using Alpinely.TownCrier;
using FLS.Common.Extensions;
using FLS.Common.Validators;
using FLS.Data.WebApi.Registrations;
using FLS.Server.Data.DbEntities;
using FLS.Server.Service.Email.Model;
using NLog;

namespace FLS.Server.Service.Email
{
    public class RegistrationEmailBuildService : EmailBuildService
    {
        public RegistrationEmailBuildService(DataAccessService dataAccessService, 
            IEmailSendService emailSendService, TemplateService templateService)
            : base(dataAccessService, emailSendService, templateService)
        {
            
        }
        
        public MailMessage CreateTrialFlightRegistrationEmailForTrialPilot(Person trialPilotPerson, DateTime selectedDate, 
            string emailRecipientAddress, Guid clubId, string locationName)
        {
            trialPilotPerson.ArgumentNotNull("trialPilotPerson");

            var model = new TrialFlightRegistrationModel()
            {
                RecipientName = trialPilotPerson.DisplayName,
                SelectedTrialFlightDate = selectedDate.ToShortDateString(),
                WillBeContactedOnDate = selectedDate.AddDays(-2).ToShortDateString(),
                LocationName = locationName
            };

            var factory = new MergedEmailFactory(new VelocityTemplateParser("TrialFlightRegistrationModel"));

            var tokenValues = new Dictionary<string, object>
                {
                    {"TrialFlightRegistrationModel", model}
                };

            return base.BuildEmail("TrialFlightRegistrationEmailForTrialPilot", factory, tokenValues, emailRecipientAddress.SanitizeEmailAddress(), clubId);
        }

        public MailMessage CreateTrialFlightRegistrationEmailForOrganisator(TrialFlightRegistrationDetails trialFlightRegistrationDetails, string emailRecipientAddress, Guid clubId, string locationName, string reservationInfo)
        {
            trialFlightRegistrationDetails.ArgumentNotNull("trialFlightRegistrationDetails");

            var model = new TrialFlightRegistrationModel()
            {
                Firstname = trialFlightRegistrationDetails.Firstname,
                Lastname = trialFlightRegistrationDetails.Lastname,
                AddressLine1 = trialFlightRegistrationDetails.AddressLine1,
                ZipCode = trialFlightRegistrationDetails.ZipCode,
                City = trialFlightRegistrationDetails.City,
                BusinessPhoneNumber = trialFlightRegistrationDetails.BusinessPhoneNumber,
                MobilePhoneNumber = trialFlightRegistrationDetails.MobilePhoneNumber,
                PrivatePhoneNumber = trialFlightRegistrationDetails.PrivatePhoneNumber,
                PrivateEmail = trialFlightRegistrationDetails.PrivateEmail,
                SelectedTrialFlightDate = trialFlightRegistrationDetails.SelectedDay.ToShortDateString(),
                WillBeContactedOnDate = trialFlightRegistrationDetails.SelectedDay.AddDays(-2).ToShortDateString(),
                LocationName = locationName,
                ReservationInformation = reservationInfo,
                Remarks = trialFlightRegistrationDetails.Remarks
            };

            if (trialFlightRegistrationDetails.InvoiceAddressIsSame)
            {
                model.InvoiceToFirstname = trialFlightRegistrationDetails.Firstname;
                model.InvoiceToLastname = trialFlightRegistrationDetails.Lastname;
                model.InvoiceToAddressLine1 = trialFlightRegistrationDetails.AddressLine1;
                model.InvoiceToZipCode = trialFlightRegistrationDetails.ZipCode;
                model.InvoiceToCity = trialFlightRegistrationDetails.City;
            }
            else
            {
                model.InvoiceToFirstname = trialFlightRegistrationDetails.InvoiceToFirstname;
                model.InvoiceToLastname = trialFlightRegistrationDetails.InvoiceToLastname;
                model.InvoiceToAddressLine1 = trialFlightRegistrationDetails.InvoiceToAddressLine1;
{'fraction_non_alphanumeric': 0.05556229528084435, 'fraction_numerical': 0.0019410408831736017, 'mean_word_length': 2.8831841733396137, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2141436', 'n_tokens_mistral': 1980, 'n_tokens_neox': 1825, 'n_words': 297}