<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Maillog extends Model
{
 	protected $dates = [''];
    protected $table = 'mail_log';

    protected $rules = array(
        
    );

    protected $injectUniqueIdentifier = true;

    public static function saveMailLog($maildata,$mailResponse)
    {
    	$mailLogObj = new Maillog();
      
      $mailLogObj->email_to=$maildata['email_to'];
      $mailLogObj->email_to_name=$maildata['email_to_name'];
      $mailLogObj->email_from=$maildata['email_from'];
      $mailLogObj->email_from_name=$maildata['email_from_name'];
      $mailLogObj->subject=$maildata['subject'];
      $mailLogObj->body=$maildata['body'];
      $mailLogObj->text=$maildata['text'];
      $mailLogObj->tag=$maildata['tag'];
      $mailLogObj->reply_to=$maildata['reply_to'];

      if(!empty($maildata['cc']))
        $mailLogObj->email_cc=$maildata['cc'];
      
      if(!empty($mailResponse)){
        if(isset($mailResponse['id']))
          $mailLogObj->mg_id = $mailResponse['id'];
        if(isset($mailResponse['message']))
          $mailLogObj->mg_response = $mailResponse['message'];
      }
      $mailLogObj->save();
      return $mailLogObj;
    }
}
