<?php

namespace FSPoster\App\Models;

use FSPoster\App\Providers\DB\BlogScope;
use FSPoster\App\Providers\DB\Model;
use FSPoster\App\Providers\DB\QueryBuilder;

/**
 * @property-read int    $id
 * @property-read string $title
 * @property-read string $content
 * @property-read string $media_ids
 * @property-read string $link
 * @property-read string $first_comment
 * @property-read int    $is_starred
 * @property-read int    $created_by
 * @property-read int    $blog_id
 * @property-read string $created_at
 * @property-read string $updated_at
 */
class ContentIdea extends Model
{
    use BlogScope
    {
        booted as private blogBoot;
    }

    protected static ?string $tableName = 'content_ideas';

    public static array $writeableColumns = [
        'id',
        'title',
        'content',
        'media_ids',
        'link',
        'first_comment',
        'is_starred',
        'created_by',
        'blog_id',
        'created_at',
        'updated_at',
    ];

    public static function booted(): void
    {
        self::blogBoot();

        self::addGlobalScope('my_content_ideas', function (QueryBuilder $builder) {
            self::onCreating(static function (QueryBuilder $builder) {
                $builder->created_by = get_current_user_id();
            });
        });
    }
}
