<?php


namespace Database;

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

class blocked extends Model
{
    protected $table = 'blocked';

    public static function getBlockeds($chatid)
    {
        return DB::table('blocked')->select('id', 'userid')->where('chatid', (string)$chatid)->get();
    }

    public static function countBlock($chatid)
    {
        return DB::table('blocked')->select('id')->where('chatid', (string)$chatid)->count();
    }

    public static function countBlocked($chatid)
    {
        return DB::table('blocked')->select('id')->where('userid', (string)$chatid)->count();
    }

    public static function hasBlockeds($chatid)
    {
        return DB::table('blocked')->select('id')->where('chatid', (string)$chatid)->exists();
    }

    public static function hasBlocked($chatid, $userid)
    {
        return DB::table('blocked')->select('id')->where('chatid', (string)$chatid)->where('userid', (string)$userid)->exists();
    }

    public static function hasUserBlocked($chatid, $userid)
    {
        return DB::table('blocked')->select('id')->where('chatid', (string)$userid)->where('userid', (string)$chatid)->exists();
    }

    public static function addBlocked($chatid, $userid)
    {
        return DB::table('blocked')->insertGetId(['chatid' => (string)$chatid, 'userid' => (string)$userid]);
    }

    public static function removeBlocked($chatid, $userid)
    {
        return DB::table('blocked')->select('id')->where('chatid', (string)$chatid)->where('userid', (string)$userid)->delete();
    }
}
