<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class CommunicationLog extends Model
{
    protected $table = 'communication_logs';

    protected $fillable = [
        'tenant_id',
        'customer_id',
        'customer_name',
        'channel',
        'direction',
        'duration',
        'message_preview',
        'timestamp',
        'agent',
        'sentiment',
        'created_by'
    ];

    protected $casts = [
        'timestamp' => 'datetime',
        'duration' => 'integer',
        'created_at' => 'datetime',
        'updated_at' => 'datetime'
    ];

    /**
     * Get the tenant that owns the communication log
     */
    public function tenant(): BelongsTo
    {
        return $this->belongsTo(Tenant::class);
    }

    /**
     * Get the customer associated with this communication
     */
    public function customer(): BelongsTo
    {
        return $this->belongsTo(User::class, 'customer_id');
    }

    /**
     * Get the user who logged this communication
     */
    public function createdByUser(): BelongsTo
    {
        return $this->belongsTo(User::class, 'created_by');
    }
}
