<?php

namespace App\Models\Communication;

use App\Models\Claim\Claim;
use App\Models\User\User;
use App\Trait\BelongsToSolicitor;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\MorphTo;

class Communication extends Model {
    protected $guarded = [];

    protected $casts = [
        'meta' => 'array',
        'started_at' => 'datetime',
        'answered_at' => 'datetime',
        'ended_at' => 'datetime',
    ];

    use BelongsToSolicitor;

    public function communicable(): MorphTo {
        return $this->morphTo();
    }

    public function claim(): BelongsTo {
        return $this->belongsTo(Claim::class, 'claim_id');
    }

    public function agent(): BelongsTo {
        return $this->belongsTo(User::class, 'agent_id');
    }

    public function call(): HasOne {
        return $this->hasOne(Call::class);
    }

    public function events(): HasMany {
        return $this->hasMany(CommunicationEvent::class);
    }

    public function recordings(): HasMany {
        return $this->hasMany(Recording::class);
    }
}