<?php

namespace Apps\Crm\Helper;

use Apps\Crm\Entity\CrmProspect;
use Apps\Crm\Entity\CrmProspectCalledBack;

class ProspectHelper {

    public static function sendContact($core, $data) {

        $prospect = new CrmProspect($core);
        $prospect->FirstName->Value =  $data["Name"] ?? "Demande de rappel";
        $prospect->LastName->Value = $data["LastName"] ?? "Demande de rappel";
        $prospect->Email->Value = $data["Email"] ?? "";
        
        $prospect->Type->Value = 1;
        $prospect->Phone->Value = $data["Phone"];
        $prospect->Description->Value = $data["Description"];

        $prospect->Save();

        $prospectId = $core->Db->GetInsertedId();

        if($data["DateCall"]){
            $calledBack = new CrmProspectCalledBack($core);
            $calledBack->ProspectId->Value = $prospectId;
            $calledBack->DateCall->Value = $data["DateCall"];
            $calledBack->HourCall->Value = $data["HourCall"];
            $calledBack->Save();
        }
    }
}
