<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

class LoginScreenNews extends Model
{
    protected $fillable = [
        'title',
        'body',
        'sort_order',
        'is_published',
        'created_by_account_id',
        'created_by_username',
        'updated_by_account_id',
        'updated_by_username',
    ];

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

    public function scopeOrdered(Builder $query): Builder
    {
        return $query
            ->orderBy('sort_order')
            ->orderByDesc('id');
    }

    public function scopePublished(Builder $query): Builder
    {
        return $query->where('is_published', true);
    }
}
