<?php

namespace App\Observers;

use Namu\WireChat\Models\Conversation;

class ConversationObserver
{
    /**
     * Handle the Conversation "created" event.
     */
    public function created(Conversation $conversation): void
    {
        // Automatically set disappearing fields (always enabled to prevent orphaned messages)
        $durationInDays = timebank_config('wirechat.disappearing_messages.duration', 30);
        $durationInSeconds = $durationInDays * 86400; // Convert days to seconds

        $conversation->disappearing_started_at = now();
        $conversation->disappearing_duration = $durationInSeconds;
        $conversation->save();
    }
}
