<?php
namespace Gisplus\Package\Crm\Models;

use DB;
use Auth;
use Gisplus\Package\Crm\Models\Lead;
use Illuminate\Database\Eloquent\Model;

class LeadStatusHistory extends Model
{
    public function leadstatus()
    {
        return $this->belongsTo(Lead::class, 'lead_id')->withDefault();

    }
    public function storeLeadStatusHistory($object)
    {
        return DB::transaction(function() use ($object){
        
            $leadstatus_history = new LeadStatusHistory;

                $leadstatus_history->lead_id                   = $object['lead'];
                $leadstatus_history->status                    = "New Contacted";
                // dd($leadstatus_history);
                $leadstatus_history->save();

            return with($leadstatus_history);
        });

    }

    public function updateLeadStatusHistory($object)
    {
        // dd($object);
        return DB::transaction(function() use ($object){
    
            $leadstatus_history = LeadStatusHistory::where('lead_id',$object['lead'])->first();
        //  dd($leadstatus_history);
            if(isset($leadstatus_history->id))
            {

                $leadstatus_history->lead_id                   = $object['lead'];
                $leadstatus_history->status                    = $object['status'];
                $leadstatus_history->save();

            }

         

            return with($leadstatus_history);
        });

    }

}
