<?php

namespace App\ValueObjects\Communications;

use App\Contracts\Communications\CommunicationSender;
use App\Models\Solicitor\Solicitor;
use App\Models\User\User;
use Illuminate\Database\Eloquent\Model;

class PlaceholderContext
{
    public function __construct(
        public readonly ?Model $messageable = null,
        public readonly ?Model $related = null,
        public readonly ?Solicitor $solicitor = null,
        public readonly ?User $user = null,
        public readonly ?CommunicationSender $sender = null,
        public readonly array $extra = [],
    ) {}

    public static function fromMessageable(
        ?Model $messageable,
        ?Model $related = null,
        ?Solicitor $solicitor = null,
        ?User $user = null,
        ?CommunicationSender $sender = null,
        array $extra = [],
    ): self {
        return new self(
            messageable: $messageable,
            related: $related,
            solicitor: $solicitor ?? app(Solicitor::class),
            user: $user ?? auth()->user(),
            sender: $sender,
            extra: $extra,
        );
    }

    public function appliesToType(): ?string
    {
        return $this->messageable?->getMorphClass() ?? ($this->messageable ? $this->messageable::class : null);
    }
}
