<?php

declare(strict_types=1);

namespace App\Notifications;

use App\Models\PropertyProposal;
use Illuminate\Notifications\Notification;

class NewProposalNotification extends Notification
{
    public function __construct(
        public PropertyProposal $proposal,
        public int $conversationId,
    ) {}

    /**
     * @return list<string>
     */
    public function via(object $notifiable): array
    {
        return ['database'];
    }

    /**
     * § 9 — le demandeur reçoit une alerte lorsqu’un professionnel répond.
     *
     * @return array<string, mixed>
     */
    public function toDatabase(object $notifiable): array
    {
        $this->proposal->loadMissing(['request', 'proposedBy']);

        $request = $this->proposal->request;
        $sender = $this->proposal->proposedBy;

        return [
            'kind' => 'new_proposal',
            'title' => __('Nouvelle réponse à votre demande'),
            'body' => __(':name a envoyé une proposition pour la demande :reference.', [
                'name' => $sender !== null ? $sender->name : __('Un professionnel'),
                'reference' => $request !== null ? $request->reference : '',
            ]),
            'request_reference' => $request !== null ? $request->reference : null,
            'request_id' => $this->proposal->request_id,
            'proposal_id' => $this->proposal->id,
            'conversation_id' => $this->conversationId,
        ];
    }
}
