<?php

namespace App\Models;

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

class ActionItem extends Model
{
    use BelongsToOwner;

    protected $table = 'meet_action_items';

    protected $fillable = [
        'uuid', 'owner_ref', 'ai_summary_id', 'assignee_ref', 'assignee_name',
        'description', 'due_date', 'status',
    ];

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

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

    public function aiSummary(): BelongsTo
    {
        return $this->belongsTo(AiSummary::class, 'ai_summary_id');
    }
}
