<?php namespace App;
use Illuminate\Http\Request;


/**
 * Created by PhpStorm.
 * User: sunil khorwal
 * Date: 27/11/19
 * Time: 1:52 PM
 */
class Templates
{
    protected $request;

    //for quicksmart
    public static $entityid = '1301159108481756475';



    public static $otp1 = 'otp1';
    public static $otp2 = 'otp2';
    public static $abort_merchant_02 = 'abort_merchant_02';
    public static $otp_termsandcondition = 'otp_termsandcondition';
    public static $rejected_application_merchant = 'rejected_application_merchant';
    public static $expiration_notification = 'expiration_notification';
    public static $rejected_customer = 'rejected_customer';
    public static $non_nach = 'non_nach';
    public static $applicaition_cancelled1 = 'applicaition_cancelled1';
    public static $otp_creationapplication = 'otp_creationapplication';
    public static $approved_customer_feedback = 'approved_customer_feedback';
    public static $greeting_01 = 'greeting_01';
    public static $approved_customer_02 = 'approved_customer_02';
    public static $multistage_disbursement_02 = 'multistage_disbursement_02';
    public static $otp_01 = 'otp_01';
    public static $alert_01 = 'alert_01';
    public static $agreementsign_customer = 'agreementsign_customer';
    public static $emandate_customer = 'emandate_customer';
    public static $disbursed_customer = 'disbursed_customer';
    public static $disbursed_customer_feedback = 'disbursed_customer_feedback';
    public static $disbursed_merchant = 'disbursed_merchant';
    public static $disbursed_feedback = 'disbursed_feedback';
    public static $pre_approved_customer_02 = 'pre_approved_customer_02';
    public static $pre_approved_merchant_02 = 'pre_approved_merchant_02';
    public static $auto_approved_abort_merchant_02 = 'auto_approved_abort_merchant_02';
    public static $thankyou_repayment = 'thankyou_repayment';
    public static $reminder_01 = 'reminder_01';
    public static $closure_link_share = 'closure_link_share';
    public static $nach = 'nach';
    public static $merchant_rds_communication1 = 'merchant_rds_communication1';
    public static $merchant_rds_communication_02 = 'merchant_rds_communication_02';
    public static $approved_customer_with_doc_01 = 'approved_customer_with_doc_01';
    public static $collection_report_doc = 'collection_report_doc';
    public static $non_starter_report_doc = 'non_starter_report_doc';
    public static $disbursed_merchant_with_doc = 'disbursed_merchant_with_doc';
    public static $disbursed_customer_with_doc_wl = 'disbursed_customer_with_doc_wl';
    public static $disbursed_customer_with_doc_la = 'disbursed_customer_with_doc_la';

    public static $pending_doc_c1 = 'pending_doc_c1';
    public static $application_processed_c1 = 'application_processed_c1';
    public static $feedback_c1 = 'feedback_c1';
    public static $approved_c1 = 'approved_c1';
    public static $approval_doc_c2 = 'approval_doc_c2';
    public static $send_disbursement_copy_c1 = 'send_disbursement_copy_c1';
    public static $send_disbursement_copy_c2 = 'send_disbursement_copy_c2';
    public static $approval_doc_c1 = 'approval_doc_c1';
    public static $rejection_c1 = 'rejection_c1';
    public static $nach_process_c1 = 'nach_process_c1';
    public static $feedback_review_c1 = 'feedback_review_c1';
    public static $disbursement_phase_c1 = 'disbursement_phase_c1';
    public static $disbursement_phase_c2 = 'disbursement_phase_c2';
    public static $application_expire_c1 = 'application_expire_c1';
    public static $loan_application_expire_v2_new = 'loan_application_expire_v2_new';
    public static $aborted_c1 = 'aborted_c1';
    public static $aborted_c2 = 'aborted_c2';
    public static $cancelled_c1 = 'cancelled_c1';
    public static $pre_approval_c1 = 'pre_approval_c1';
    public static $sign_agreement_c1 = 'sign_agreement_c1';
    public static $agrement_signing_thanks_v1 = 'agrement_signing_thanks_v1';
    public static $application_received_c1 = 'application_received_c1';
    public static $application_received_sec_c1 = 'application_received_sec_c1';
    public static $application_received_sec_c2 = 'application_received_sec_c2';
    public static $revised_loan_agreement_c1 = 'revised_loan_agreement_c1';
    public static $revised_loan_agreement_c2 = 'revised_loan_agreement_c2';
    public static $disbursement_advice_c1 = 'disbursement_advice_c1';
    public static $disbursement_advice_c2 = 'disbursement_advice_c2';
    public static $failed_promise_emi_c1 = 'failed_promise_emi_c1';
    public static $failed_promise_emi_c2 = 'failed_promise_emi_c2';
    public static $net_banking_statement_c1 = 'net_banking_statement_c1';
    public static $net_banking_statement_c2 = 'net_banking_statement_c2';
    public static $missed_call_c1 = 'missed_call_c1';
    public static $missed_call_c2 = 'missed_call_c2';
    public static $disbursement_c1 = 'disbursement_c1';
    public static $project_lead_copy_consumer = 'project_lead_copy_consumer';
    public static $merchant_relation_manager_change = 'merchant_relation_manager_change';
    public static $nach_new_v2 = 'nach_new_v2';


    public static $admin_app_received = 'admin_app_received';
    public static $admin_app_received_1 = 'admin_app_received_1';
    public static $website_app_received = 'website_app_received';
    public static $customer_app_received = 'customer_app_received';
    public static $merchant_app_received = 'merchant_app_received';
    public static $stop_message = 'stop_message';
    public static $rate_service = 'rate_service';


    public static $admin_app_received_v1 = 'admin_app_received_v1';
    public static $website_app_received_v1 = 'website_app_received_v1';

    public static $admin_app_received_1_v1 = 'admin_app_received_1_v1';
    public static $customer_app_received_v1 = 'customer_app_received_v1';
    public static $merchant_app_received_v1 = 'merchant_app_received_v1';

    public static $admin_app_received_1_v2 = 'admin_app_received_1_v2';
    public static $admin_app_received_2_v2 = 'admin_app_received_2_v2';
    public static $customer_app_received_v2 = 'customer_app_received_v2';
    public static $merchant_app_received_v2 = 'merchant_app_received_v2';


    public static $stop_message_v1 = 'stop_message_v1';
    public static $stop_message_merchant_v1 = 'stop_message_merchant_v1';
    public static $rate_service_v1 = 'rate_service_v1';
    public static $rate_service_v2 = 'rate_service_v2';
    public static $document_message_bot = 'document_message_bot_v3';
    public static $download_consumer_app_v2 = 'download_consumer_app_v2';
    public static $apply_loan_application_v1 = 'apply_loan_application_v1';
    public static $loanshastra_nondownload_app_v1 = 'loanshastra_nondownload_app_v1';

    public static $issue_faced_service = 'issue_faced_service';
    public static $issue_faced_service_sec = 'issue_faced_service_sec';
    public static $issue_faced_service_thr = 'issue_faced_service_thr';
    public static $nach_aaddhar_v1 = 'nach_aaddhar_v1';
    public static $addhar_link_nach_rm_v1 = 'addhar_link_nach_rm_v1';
    public static $telecom_otp = 'telecom_otp';

    public static $consent_bureau_pull_v1 = 'consent_bureau_pull_v1';


    public static $approved_processingfee = 'approved_processingfee';
    public static $approved_processingfee_insurancefee = 'approved_processingfee_insurancefee';
    public static $approved_processingfee_insurancefee_advance_amount = 'approved_processingfee_insurancefee_advance_amount';
    public static $bnpl_approva_v1 = 'bnpl_approva_v1';
    public static $approved_insurancefee = 'approved_insurancefee';
    public static $advance_amount_cust_pay = 'advance_amount_cust_pay';
    public static $lightning_disbursed_merchant_represntative = 'lightning_disbursed_merchant_represntative';

    public static $applicant_approve_partner = 'applicant_approve_partner';

    public static $customer_app_received_avanse = 'customer_app_received_avanse';
    public static $disbursed_customer_with_doc_avanse = 'disbursed_customer_with_doc_avanse';

    public static $cf_approved = 'cf_approved';

    protected $templateId;
    protected $key;
    protected $templateArgs = array();


    public static $acceptedTemplates = [
            "otp1" => [
                "channel"=> "whatsapp",
                "templateId"=> "otp1",
                "templateLanguage"=> "en",
                "isRichTemplate"=> false,
                "templateDesc"=> "Your Credit Fair verification code is {{1}}",
            ],
            "applicaition_cancelled1" => [
                "channel"=> "whatsapp",
                "templateId"=> "applicaition_cancelled1",
                "templateLanguage"=> "en",
                "isRichTemplate"=> false,
                "templateDesc"=> "Dear {{1}} \n\nWe wanted to update you on the status of your loan application. The loan application has been cancelled since we haven't received the required documents post approval. Please contact the us if there has been an error.\n\nBest Regards,\nTeam Credit Fair",
            ],
            "otp2" => [
                "channel"=> "whatsapp",
                "templateId"=> "otp2",
                "templateLanguage"=> "en",
                "isRichTemplate"=> false,
                "templateDesc"=> "By validating OTP {{1}} I agree to Credit Fair's terms and conditions provided here - {{2}}, for the loan application and have no objection to them conducting a credit check",
            ],
            "otp_termsandcondition" => [
                "channel"=> "whatsapp",
                "templateId"=> "otp_termsandcondition",
                "templateLanguage"=> "en",
                "isRichTemplate"=> false,
                "templateDesc"=> "By sharing otp you agree to Credit Fair's terms and conditions provided here - {{1}} for the loan application and have no objection to them conducting a credit check",
            ],
            "otp_creationapplication" => [
                "channel"=> "whatsapp",
                "templateId"=> "otp_creationapplication",
                "templateLanguage"=> "en",
                "isRichTemplate"=> false,
                "templateDesc"=> "By validating *OTP {{1}}* I agree to Credit Fair's terms and conditions provided here - {{2}} for the loan application and have no objection to them conducting a credit check",
            ],
            "expiration_notification" => [
                "channel"=> "whatsapp",
                "templateId"=> "expiration_notification",
                "templateLanguage"=> "en",
                "isRichTemplate"=> false,
                "templateDesc"=> "Dear {{1}}, \n\nKindly note that the your loan application will expire {{2}}, upon not receiving the required documents. A complete loan application can improve your credit score. Therefore, we would advise you to send in the documents at the earliest. Let us know if you have any questions.\n\nBest Regards,\nTeam Credit Fair",
            ],
            "approved_customer_feedback" => [
                "channel"=> "whatsapp",
                "templateId"=> "approved_customer_feedback",
                "templateLanguage"=> "en",
                "isRichTemplate"=> false,
                "templateDesc"=> "Dear {{1}}, \n\nPlease leave your feedback about our service on Google Reviews {{2}} to help us provide you with a better experience and stay updated on Credit Fair by liking our page on Facebook at {{3}}. \n\nBest, \nTeam Credit Fair \nPhone=> {{4}}",
            ],
            "greeting_01" => [
                "channel"=> "whatsapp",
                "templateId"=> "greeting_01",
                "templateLanguage"=> "en",
                "isRichTemplate"=> false,
                "templateDesc"=> "Thank you for contacting Credit Fair! How can we help you?",
            ],
            "approved_customer" => [
                "channel"=> "whatsapp",
                "templateId"=> "approved_customer",
                "templateLanguage"=> "en",
                "isRichTemplate"=> false,
                "templateDesc"=> "Dear {{1}}, \n\nYour application {{2}} for an Easy EMI plan for purchase at {{3}} has been approved! Congratulations and welcome to the Credit Fair family! \n\nReview your sanction letter at {{4}}. \nYou can sign off, on the loan agreement online here - {{5}}. \n\nBest, \nTeam Credit Fair \nPhone=> {{6}}",
            ],
            "otp_01" => [
                "channel"=> "whatsapp",
                "templateId"=> "otp_01",
                "templateLanguage"=> "en",
                "isRichTemplate"=> false,
                "templateDesc"=> "Your OTP for this transaction is *{{1}}*\n\n-----------------------------\n_Never share it with anyone. Credit Fair never calls to verify it._",
            ],
            "alert_01" => [
                "channel"=> "whatsapp",
                "templateId"=> "alert_01",
                "templateLanguage"=> "en",
                "isRichTemplate"=> false,
                "templateDesc"=> "Customer Name=> *{{1}} *\nCommented By=> *{{2}}*\nText of Comment=> _{{3}}_\nApplication Edit=> {{4}}",
            ],
            "rejected_customer" => [
                "channel"=> "whatsapp",
                "templateId"=> "rejected_customer",
                "templateLanguage"=> "en",
                "isRichTemplate"=> false,
                "templateDesc"=> "Dear {{1}},\nWe cannot approve your application of Rs {{2}}. We'd be happy to reconsider you after 3 months.",
            ],
            "rejected_application_merchant" => [
                "channel"=> "whatsapp",
                "templateId"=> "rejected_application_merchant",
                "templateLanguage"=> "en",
                "isRichTemplate"=> false,
                "templateDesc"=> "Dear {{1}}, \n\nWe regret to inform you that we cannot approve {{2}} request at this time. We'd be happy to reconsider them after 3 months. If you have any questions about our decision, please free to contact us at {{3}}.\n\nRegards,\nTeam Credit Fair",
            ],
            "agreementsign_customer" => [
                "channel"=> "whatsapp",
                "templateId"=> "agreementsign_customer",
                "templateLanguage"=> "en",
                "isRichTemplate"=> false,
                "templateDesc"=> "Dear {{1}}, \nThanks for signing the loan agreement for your purchase from {{2}} of Rs {{3}} and loan ID {{4}}. \n\nPlease complete pending requirements to arrange the disbursement",
            ],
            "emandate_customer" => [
                "channel"=> "whatsapp",
                "templateId"=> "emandate_customer",
                "templateLanguage"=> "en",
                "isRichTemplate"=> false,
                "templateDesc"=> "Dear {{1}},\n\nTo finalise your Easy EMI plan at {{2}}, please register the auto-debit mandate by clicking here=> {{3}} \n\nYou will be completing the process on a secure site run by the regulator, NPCI and the same will require your Debit Card OR Net Banking details. Your data is secured by bank grade encryption. \n\nIn case you face any issues, please contact Credit Fair at=> {{4}}\n\nBest,\nTeam Credit Fair \nPhone=> {{5}}",
            ],
            "disbursed_customer" => [
                "channel"=> "whatsapp",
                "templateId"=> "disbursed_customer",
                "templateLanguage"=> "en",
                "isRichTemplate"=> false,
                "templateDesc"=> "Dear {{1}}, \n\nThanks for choosing Credit Fair & welcome on-board! Please review your=>\n- Welcome letter @ {{2}} , \n- Loan Documents @ {{3}} \n\nBest,\nTeam Credit Fair \nPhone=> {{4}}",
            ],
            "disbursed_customer_feedback" => [
                "channel"=> "whatsapp",
                "templateId"=> "disbursed_customer_feedback",
                "templateLanguage"=> "en",
                "isRichTemplate"=> false,
                "templateDesc"=> "Dear {{1}},\n\nPlease leave your feedback about our service on Google Reviews at {{2}}, to help us provide you with a better experience. Stay in touch with Credit Fair by liking our page on Facebook - {{3}}.\n\nBest,\nTeam Credit Fair \nPhone=> {{4}}",
            ],
            "disbursed_merchant" => [
                "channel"=> "whatsapp",
                "templateId"=> "disbursed_merchant",
                "templateLanguage"=> "en",
                "isRichTemplate"=> false,
                "templateDesc"=> "Dear {{1}},\n\nA payment of Rs {{2}} on behalf of {{3}} has been sent to your  account ending in {{4}} . \nNow, you can proceed with the delivery of your product / service to {{5}}.\n\nRegards, \nTeam Credit Fair,\nPhone=> {{6}}",
            ],
            "disbursed_feedback" => [
                "channel"=> "whatsapp",
                "templateId"=> "disbursed_feedback",
                "templateLanguage"=> "en",
                "isRichTemplate"=> false,
                "templateDesc"=> "Dear {{1}}, \n\nPlease provide your feedback here - {{2}} to help us provide you with a better experience. It will only take a few seconds. If you are happy with our service, please like our page on Facebook {{3}}.\n\nBest, \nTeam Credit Fair \nPhone=> {{4}}",
            ],
            "abort_merchant" => [
                "channel"=> "whatsapp",
                "templateId"=> "abort_merchant",
                "templateLanguage"=> "en",
                "isRichTemplate"=> false,
                "templateDesc"=> "Dear {{1}}, \n\nWe wanted to update you on the status of {{2}} loan application. The application has been aborted by the customer. Please contact the customer or us at {{3}} if there has been an error. \n\nRegards, \nTeam Credit Fair",
            ],
            "pre_approved_customer" => [
                "channel"=> "whatsapp",
                "templateId"=> "pre_approved_customer",
                "templateLanguage"=> "en",
                "isRichTemplate"=> false,
                "templateDesc"=> "Dear {{1}},\n\nCongrats! You are pre-approved up to Rs {{2}} subject to submission of following documents=> {{3}} Please note that the final loan amount and offer might change. The pre-approval will expire on {{4}}.\n\nRegards,\nTeam Credit Fair",
            ],
            "pre_approved_merchant" => [
                "channel"=> "whatsapp",
                "templateId"=> "pre_approved_merchant",
                "templateLanguage"=> "en",
                "isRichTemplate"=> false,
                "templateDesc"=> "Dear {{1}},\n\nCongrats! {{2}} has been pre-approved up to Rs {{3}} subject to submission of following documents=>{{4}} Please note that the final amount might vary. The pre-approval will expire on {{5}}.\n\n*Warning=> Dont deliver product/service until we have sent disbursement of funds*\n\nRegards,\nTeam Credit Fair",
            ],
            "auto_approved_abort_merchant" => [
                "channel"=> "whatsapp",
                "templateId"=> "auto_approved_abort_merchant",
                "templateLanguage"=> "en",
                "isRichTemplate"=> false,
                "templateDesc"=> "Dear {{1}},\n\nKindly note that the {{1}} approved loan application will expire on {{2}}, upon not receiving the required documents. Please follow-up on the same, to proceed with the disbursement.\n\nBest Regards,\nTeam Credit Fair",
            ],
            "thankyou_repayment" => [
                "channel"=> "whatsapp",
                "templateId"=> "thankyou_repayment",
                "templateLanguage"=> "en",
                "isRichTemplate"=> false,
                "templateDesc"=> "Dear {{1}},\n\nThanks for your payment of Rs {{2}} for your loan ID {{3}} on {{4}} with transaction ID {{5}}. Every repayment can help you improve your credit history, leading to lower interest costs or access to larger loans. Let us know if you have any questions.\n\nRegards,\nTeam Credit Fair\nPhone=> {{6}}",
            ],
            "reminder_01" => [
                "channel"=> "whatsapp",
                "templateId"=> "reminder_01",
                "templateLanguage"=> "en",
                "isRichTemplate"=> false,
                "templateDesc"=> "Dear {{1}},\n\nYou are {{2}} days late on your payment of Rs. {{3}} due towards. EMI of Rs {{4}} and fees of Rs {{5}}. \nPay now on {{6}}. \nCall us on {{7}} if you need any help or have already paid.\n\nRegards,\nTeam Credit Fair",
            ],
            "closure_link_share" => [
                "channel"=> "whatsapp",
                "templateId"=> "closure_link_share",
                "templateLanguage"=> "en",
                "isRichTemplate"=> false,
                "templateDesc"=> "Dear {{1}},\n\nPlease pay amount of Rs. {{2}} by clicking on {{3}}",
            ],
            "non_nach" => [
                "channel"=> "whatsapp",
                "templateId"=> "non_nach",
                "templateLanguage"=> "en",
                "isRichTemplate"=> false,
                "templateDesc"=> "Dear {{1}},\n\nAn installment of Rs {{2}} for your purchase from {{3}} is due on {{4}} for your loan application no. {{5}}. Since your Auto Debit i.e. NACH mandate has not yet been registered, please pay the EMI using {{6}} . \n\nYou can reach us on phone at {{7}} or email at {{8}} if you have any questions.\n\nBest Regards,\nTeam Credit Fair",
            ],
            "nach" => [
                "channel"=> "whatsapp",
                "templateId"=> "nach",
                "templateLanguage"=> "en",
                "isRichTemplate"=> false,
                "templateDesc"=> "Dear {{1}},\n\nEMI of Rs {{2}} will be debited on {{3}} for your loan application no. {{4}}. Please ensure balance in your {{5}} account number ending with {{6}}, at least one day before. Please note that it would take 3 working days to update payment in our system post debit from your account.\n\nBest Regards,\nTeam Credit Fair",
            ],
            "merchant_rds_communication1" => [
                "channel"=> "whatsapp",
                "templateId"=> "merchant_rds_communication1",
                "templateLanguage"=> "en",
                "isRichTemplate"=> false,
                "templateDesc"=> "Dear {{1}},\n\nLogin {{2}} applications using Credit Fair’s App with minimum approval amount of {{3}} to receive {{4}}. You may login applications @ {{5}}.\n\nRegards,\nTeam Credit Fair",
            ],
            "merchant_rds_communication2" => [
                "channel"=> "whatsapp",
                "templateId"=> "merchant_rds_communication2",
                "templateLanguage"=> "en",
                "isRichTemplate"=> false,
                "templateDesc"=> "Dear {{1}},\n\nEarnings=> *{{2}}*\nLogin {{3}} applications with the disbursal amount of {{3}} before {{4}} to {{5}}. \nYou may login applications @ {{6}}.\n\nRegards,\nTeam Credit Fair",
            ],
            "applicant_approve_partner" => [
                "channel"=> "whatsapp",
                "templateId"=> "applicant_approve_partner",
                "templateLanguage"=> "en",
                "isRichTemplate"=> false,
                "templateDesc"=> "Dear {{1}},\n\nWe are happy to inform you that your loan has been approved for an amount of Rs {{2}} towards your purchase at {{3}}. Track your application on our app {{4}}.\n\nThanks, Team Credit Fair"
            ],
    ];


    /**
     * WhatsApp constructor.
     * @param Request $request
     */
    public function __construct(Request $request){
        $this->request = $request;
        $this->templateId = $this->request->get('templateId') ? $this->request->get('templateId') : '';
        $this->templateArgs = $this->request->get('templateArgs') ? $this->request->get('templateArgs') : array();
        $this->key = $this->request->get('message_type') == 'payment' ? _env('PAYMENT_KEY') : _env('CREDIT_KEY');
    }

    public static function getTemplateBody($templateId, $args = [])
    {
        if (!isset(self::$acceptedTemplates[$templateId])) {
            return null; // template not found
        }

        $template = self::$acceptedTemplates[$templateId]['templateDesc'];

        foreach ($args as $index => $value) {
            $placeholder = '{{' . ($index + 1) . '}}';
            $template = str_replace($placeholder, $value, $template);
        }

        return $template;
    }
}
