<?php
/**
 * Created by PhpStorm.
 * User: sunil
 * Date: 10/27/18
 * Time: 2:53 PM
 */

namespace App;


use Illuminate\Database\Eloquent\Model;
use App\Scopes\MessageScope;

class Lenders extends Model
{
    use Encryptable;
    protected $table = 'lenders';

    protected $fillable = ['id', 'name', 'logo', 'cin', 'email', 'website', 'signature', 'signed_by', 'address', 'state', 'city', 'country', 'pincode', 'agreement', 'status', 'created_by', 'updated_by', 'deleted_at', 'created_at', 'updated_at', 'registaration_date', 'SubRegistrar', 'vide_registration', 'firstpage', 'lastpage', 'gst', 'pan', 'phone', 'companies_act','product_type_details','is_hypothecation_active', 'activate_insurance'];

    public static $encryptable = ['email', 'phone'];
    protected static function boot()
    {
        parent::boot();
        static::addGlobalScope(new MessageScope(static::$encryptable));
    }

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

    public function banks(){
        return $this->hasMany('App\LenderBank','lender_id','id');
    }

    public function language_consent(){
        return $this->hasMany('App\LenderLanguageConsent','lender_id','id')->where('status',1);
    }

    public function merchant_whitelist(){
        return $this->hasMany('App\MerchantWhitelistLender','lender_id','id');
    }
}