<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use App\Scopes\MessageScope;
use Illuminate\Support\Facades\DB;


class ConsumerApplicationElement extends Model
{
    use Encryptable;

    protected $table = 'consumer_application_element';
    protected $casts = [
        'type_of_customer' => 'integer',
        'solar_power_type' => 'integer',
        'inverter_KW_installation' => 'string',
        'inverter_power_savings' => 'string',
        'application_id' => 'integer'
    ];
    public $fillable = ['application_id','industry','profession_type','co_applicant_industry','co_applicant_profession_type','negative_profile','work_email','center_id','gst_number','current_address_lat_long','permanent_address_lat_long','current_address_text','current_formatted','permanent_address_text','permanent_formatted_text','designation','department','contact','is_auto_approved','telecom_response','product_name','foreclosure_date','is_reviewed','preferred_language','co_applicant_for_signing','co_applicant_for_income','bank_id','mandatory_document_list','auto_document_rule_id','amount_over_due','total_amount_due','last_emi_date','emi_paid','emi_pending','pre_approved_id','agreement_version','product_id','duration','collection_advisor','payment_transfer_date','hold_amount','withhold_adjusted', 'reason_for_loan', 'is_payout','reference_name_1','reference_name_2','reference_contact_1','reference_contact_2','reference_relation_1','reference_relation_2','onfido_skip', 'agreement_resign','nominee_salutation','nominee_full_name','nominee_dob','nominee_gender','nominee_relationship','nominee_mobile_number', 'video_kyc','reference_number', 'co_app_onfido_skip', 'merchant_representative_name','merchant_representative_mobile','merchant_representative_email', 'unique_id_number', 'avanse_customer_id','co_applicant_designation','admission_status', 'principal_due', 'total_principal_due', 'father_name', 'co_applicant_father_name', 'foreclosure_amount_sent', 'foreclosure_link_sent_by', 'loan_applied_for', 'loan_applied_for_mobile', 'loan_applied_for_relation', 'pf_discount', 'onefin_id','education_level','mother_name','applicant_caste','loan_type','applicant_religion','type_of_customer_application','type_of_entity','tax_residency_app','tax_residency_co_app','type_of_customer_sub_category', 'co_applicant_industry','co_applicant_profession_type','center_id','created_at','updated_at','current_address_text','current_formatted_text','permanent_address_text','permanent_formatted_text','is_auto_approved','designation','department','contact','product_name','preferred_language','co_applicant_for_signing','co_applicant_for_income','bank_id','mandatory_document_list','mandatory_details_list','type_of_customer','solar_power_type','risk_category','inverter','inverter_model_description','inverter_monthly_power_bill','inverter_kw_installation','amount_over_due','inverter_power_savings','electricity_name_change'];

    public static $encryptable = [
        'contact',
        'telecom_response',
        'nominee_mobile_number',
        'merchant_representative_mobile',
        'merchant_representative_email',
    ];
    protected static function boot()
    {
        parent::boot();
        static::addGlobalScope(new MessageScope(static::$encryptable));
    }
    public function merchant_center()
    {
        return $this->hasOne('App\MerchantLocation','id','center_id');
    }

    public function collection_executive(){
        return $this->hasOne('App\User','id','collection_advisor');
    }

    public function application(){
        return $this->hasOne('App\ConsumerApplication','id','application_id');
    }

    public function disbursedFromBank(){
        return $this->hasOne('App\LenderBank','id','bank_id');
    }

    public function product() {
        return $this->hasOne('App\Products','id','product_name');
    }

    public function vendor() {
        return $this->hasOne('App\Vendor','id','vendor_id');
    }
}
