<?php

namespace App\Models;

/**
 * See CreateAiDailyBriefingsTable's migration comment. Written only by
 * DailyBriefingService::generateForCurrentTenant() — every other caller
 * (the Dashboard card, the ai:daily-briefing command) only ever reads.
 */
class AiDailyBriefingModel extends TenantModel
{
    protected $table            = 'ai_daily_briefings';
    protected $primaryKey       = 'id';
    protected $useAutoIncrement = true;
    protected $returnType       = 'object';
    protected $useTimestamps    = true;
    protected $createdField     = 'created_at';
    protected $updatedField     = '';

    protected $allowedFields = [
        'briefing_date',
        'summary_text',
        'data_snapshot',
    ];

    public function forDate(string $date): ?object
    {
        return $this->where('briefing_date', $date)->first();
    }

    public function today(): ?object
    {
        return $this->forDate(date('Y-m-d'));
    }
}
