<?php

namespace App\Models;

use App\Models\Concerns\BelongsToOwner;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Str;

class AiSummary extends Model
{
    use BelongsToOwner;

    protected $table = 'meet_ai_summaries';

    protected $fillable = [
        'uuid', 'owner_ref', 'session_id', 'transcript_id', 'status',
        'summary', 'decisions',
    ];

    protected function casts(): array
    {
        return ['decisions' => 'array'];
    }

    protected static function booted(): void
    {
        static::creating(function (AiSummary $summary) {
            if (empty($summary->uuid)) {
                $summary->uuid = (string) Str::uuid();
            }
        });
    }

    public function getRouteKeyName(): string
    {
        return 'uuid';
    }

    public function session(): BelongsTo
    {
        return $this->belongsTo(Session::class, 'session_id');
    }

    public function transcript(): BelongsTo
    {
        return $this->belongsTo(Transcript::class, 'transcript_id');
    }

    public function actionItems(): HasMany
    {
        return $this->hasMany(ActionItem::class, 'ai_summary_id');
    }
}
