<?php

namespace Database;

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

class Groups extends Model
{
    protected $table = 'groups';

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

    public static function hasGroup($chatid)
    {
        return DB::connection('sqlite')->table('groups')->where('chatid', str_replace('-', '', $chatid))->exists();
    }

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

    public static function addGroup($chatid)
    {
        return DB::connection('sqlite')->table('groups')->insertGetId(['chatid' => str_replace('-', '', $chatid)]);
    }

    public static function removeGroup($chatid)
    {
        return DB::connection('sqlite')->table('groups')->where('chatid', str_replace('-', '', $chatid))->delete();
    }

}
