<?php

namespace App\Models\Communication;

use App\Models\Solicitor\Solicitor;
use App\Models\User\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class Call extends Model {
    /**
     * Disposition an agent selects at wrap-up to mark a call as the first
     * substantive client conversation. ClassifyAndScoreCallJob treats this as an
     * authoritative "initial call" signal: it skips the AI classifier and scores
     * the transcript directly against the compliance scorecard.
     */
    public const DISPOSITION_INITIAL_CALL = 'initial_call';

    protected $guarded = [];

    protected $casts = [
        'meta' => 'array',
        'queued_at' => 'datetime',
        'connected_at' => 'datetime',
        'wrap_up_until' => 'datetime',
        'callback_at' => 'datetime',
        'is_recorded' => 'boolean',
        'recording_notice_played' => 'boolean',
    ];

    public function communication(): BelongsTo {
        return $this->belongsTo(Communication::class);
    }

    public function solicitor(): BelongsTo {
        return $this->belongsTo(Solicitor::class);
    }

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

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

    public function phoneNumber(): BelongsTo {
        return $this->belongsTo(SolicitorPhoneNumber::class, 'solicitor_phone_number_id');
    }

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