<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class ClientLog extends Model
{
    const TABLE = 'agent.dbo.client_log';
    protected $table = self::TABLE;
    public $timestamps = false;

    protected $fillable = [
        'log_type',
        'userID',
        'Channel',
        'campaign_id',
        'ad_id',
        'pixel',
        'pixelID',
        'log_date',
        'created_at'
    ];

    /**
     * Add client log
     * @param array $data
     * @return bool
     */
    public static function addLog(array $data)
    {
        $logData = [
            'log_type' => $data['log_type'] ?? '',
            'userID' => $data['userID'] ?? null,
            'Channel' => $data['Channel'] ?? null,
            'campaign_id' => $data['campaign_id'] ?? null,
            'ad_id' => $data['ad_id'] ?? null,
            'pixel' => $data['pixel'] ?? null,
            'pixelID' => $data['pixelID'] ?? null,
            'log_date' => $data['log_date'] ?? date('Y-m-d'),
            'created_at' => date('Y-m-d H:i:s')
        ];

        return self::insert($logData);
    }
}
