<?php

namespace App;

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


class MerchantLocation extends Model
{
    use SoftDeletes;
    use Encryptable;

    protected $table = 'merchant_location';

    public static $encryptable = [
        'gst_number'
    ];
    protected static function boot()
    {
        parent::boot();
        static::addGlobalScope(new MessageScope(static::$encryptable));
    }
    protected $fillable = ['name', 'slug', 'email', 'phone', 'location','gst_number','state','total_revenue_per_month','percentage_of_sales_in_emi','number_of_lenders','number_of_visits','landmark','target_number_application','target_value_application','avg_ticket_size','rm_id'];

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

    public function merchant(){
        return $this->hasOne('App\Merchant','id','merchant_id');
    }

    public function gst_filling_data()
    {
        return $this->hasMany('App\MerchantGstFillingData','merchant_id','id')->where('type','merchant_location_id');
    }

    public function calls(){
        return $this->hasMany('App\CallLogs','_id','id')->where('id_type','merchant_location_id')->where(function ($query) {
            $query->whereNull('status')
                ->orWhereIn('status', ['in-progress','ringing']);
        });
    }
    public function rmDetails(){
        return $this->hasOne('App\User','id','rm_id')->whereNull('deleted_at');
    }
}
