<?php


namespace Database;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Capsule\Manager as DB;

class Listbots extends Model
{
    protected $table = 'list_bot';

    public static function getBot($username)
    {
        return DB::connection('sqlite')->table('list_bot')->where('bot', $username)->first();
    }

    public static function getBots()
    {
        return DB::connection('sqlite')->table('list_bot')->get();
    }

    public static function getBotDef()
    {
        return DB::connection('sqlite')->table('list_bot')->where('def', true)->first();

    }

    public static function hasBots()
    {
        return DB::connection('sqlite')->table('list_bot')->exists();
    }

    public static function hasBot($username)
    {
        return DB::connection('sqlite')->table('list_bot')->where('bot', $username)->exists();
    }

    public static function addBot($username, $token)
    {
        return DB::connection('sqlite')->table('list_bot')->insertGetId(['bot' => $username, 'token' => $token]);
    }

    public static function removeBot($username)
    {
        return DB::connection('sqlite')->table('list_bot')->where('bot', $username)->delete();
    }

    public static function updateDef($username, $values)
    {
        DB::connection('sqlite')->table('list_bot')->where('bot', $username)->update(['def' => $values]);
        return true;
    }

    public static function updateToken($username, $values)
    {
        DB::connection('sqlite')->table('list_bot')->where('bot', $username)->update(['token' => $values]);
        return true;
    }

    public static function removeDefults()
    {
        DB::connection('sqlite')->table('list_bot')->update(['def' => false]);
        return true;
    }
}
