<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use App\Models;
#use Spatie\Activitylog\Traits\LogsActivity;
//use Spatie\Activitylog\Traits\CausesActivity;
#use Spatie\Activitylog\LogOptions;

class Client extends Model
{
    #use LogsActivity;

    protected $guarded = array('id');
  	public $table = "clients";
    protected $appends = ['client_services'];
    /*
    protected static $logName = 'clients_log';
    protected static $logOnlyDirty = true;
    protected static $dontSubmitEmptyLogs = true;


  	protected static $logUnguarded = true;
    public function getActivitylogOptions(): LogOptions{
        return LogOptions::defaults()
          ->logUnguarded()->useLogName('client')->logOnlyDirty()->dontSubmitEmptyLogs();
    }
    */

    /*
    public function getprogressIndicatorsAttribute($value){
      $current_indicator_count = json_decode($value, true);
      $general_indicators = Models\ClientIndicator::count();
      $indicator_score = (count($current_indicator_count)/$general_indicators) * 100;
      return number_format($indicator_score);
    }


    public function getOnboardingProgressStageAttribute($value){
      $onboarding_stage = json_decode($value, true);

      // $indicator_score = (count($current_indicator_count)/$general_indicators) * 100;
      return $onboarding_stage[0];
    }
    */
  	public function country_info(){
  		return $this->hasOne('App\Models\Country', 'alpha_2_code', 'country');
  	}
    public function country_flag_info(){
      return $this->hasOne('App\Models\CountryFlag', 'country', 'country');
    }
  	public function payment_type_info(){
  		return $this->hasOne('App\Models\PaymentType', 'id', 'pay_mode');
  	}

  	public function service_info(){
      #return $this->hasMany('App\Comment', 'foreign_key', 'local_key');
  		return $this->hasMany('App\Models\ClientCategory', 'client_id', 'id');
  	}
    public function report_info(){
      return $this->hasMany('App\Models\MeetingReport', 'client', 'id');
    }
    public function auth_user_info(){
      return $this->hasOne('App\Models\SystemUser', 'id', 'auth_user_id');
    }
    public function created_by_info(){
      return $this->hasOne('App\Models\SystemUser', 'id', 'created_by');
    }
    public function modified_by_info(){
      return $this->hasOne('App\Models\SystemUser', 'id', 'last_modified_by');
    }
    public function short_code_info(){
      return $this->hasMany('App\Models\ShortCode', 'client_id', 'id');
    }


    public function getClientServicesAttribute(){
        $services = $this->service_info;
        $service_name_arr = [];
        foreach ($services as $value) {
          $service_name = Models\Service::find($value['category_id']);
          $service_name_arr[] = $service_name->name;
        }
        return $service_name_arr;
    }

}
