<?php

namespace App\Services;

use App\Models\LoginScreen;
use App\Services\DataService;
use Illuminate\Support\Facades\DB;

class LoginScreenDataService extends DataService
{


    /**
     * Deactivate all login screens with the exception of one
     * 
     * @param int $exclude
     */
    public static function deactivateOtherScreens(int $exclude): void
    {
        DB::table('login_screens')
            ->where('id', '<>', $exclude)
            ->update(['active' => 0]);
    }


    /**
     * Gets the active login screen
     * 
     * @return ?LoginScreen
     * 
     */
    public static function getActiveScreen(): ?LoginScreen
    {
        return LoginScreen::full()
            ->with('image')
            ->where('status', 'published')
            ->where('active', 1)
            ->first();
    }
}
