<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

use App\DB;

class CallCenter extends Model
{

    private $generic_condition;
  

    public function __construct()
    {
           
       $this->setCondition(['is_recycle' => '0']);
    }

    public function setCondition($condition = [])
    {
        $this->generic_condition = $condition;
    }

    public function getCondition()
    {
        return $this->generic_condition;
    }

	
	public function storeCall($object)
	{
		return \DB::transaction(function () use ($object)  {

			$call             = new CallCenter;
			$call->name       = $object['name'];
			$call->cnic       = $object['cnic'];
			$call->contact    = $object['contact'];
			$call->interest   = $object['interest'];

			return $call->save();

		});
	}
	 public function updateCall($object,$id)
    {
        
       return  \DB::transaction(function () use ($object,$id)  {

           $call = CallCenter::find($id);

            if(isset($call->id))
            {

            $call->name           = $object['name'];

            $call->cnic           = $object['cnic'];

            $call->contact        = $object['contact'];

            $call->interest        = $object['interest'];

           return  $call->update();
           }
           else
           {

            return 0;
           }

          


        });

    }

	public function getCallsList()
	{

		return CallCenter::where($this->getCondition())->get();
	}
	public function removeCall($id)
    {
        return \DB::transaction(function () use ($id) {

            $call = CallCenter::find($id);

            if(isset($call->id))
            {
                
              $call->is_recycle   = '1';

              $call->update();

                return 1;
            }
            
            return 0;
        });
    }

}
