<?php


namespace Database;

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

class Botads extends Model
{
    protected $table = 'bot_ads';


    public static function getAllAds()
    {
        return DB::connection('sqlite')->table('bot_ads')->where('status', true)->get();
    }

    public static function getAds($id)
    {

        return DB::connection('sqlite')->table('bot_ads')->where('id', $id)->first();
    }

    public static function hasAdss()
    {
        return DB::connection('sqlite')->table('bot_ads')->select('id')->where('status', true)->exists();
    }

    public static function hasAds($id)
    {
        return DB::connection('sqlite')->table('bot_ads')->select('id')->where('id', $id)->exists();

    }

    public static function addAds($chatid, $msgid, $max_view)
    {
        return DB::connection('sqlite')->table('bot_ads')->insertGetId(['chatid' => $chatid, 'msgid' => $msgid, 'max_view'=> $max_view]);

    }

    public static function updateView($id, $values)
    {
        DB::connection('sqlite')->table('bot_ads')->where('id', $id)->update(['view' => $values]);
        return true;
    }

    public static function updateViewMax($id, $values)
    {
        DB::connection('sqlite')->table('bot_ads')->where('id', $id)->update(['max_view' => $values]);
        return true;
    }

    public static function updateBtnTitle($id, $values)
    {
        DB::connection('sqlite')->table('bot_ads')->where('id', $id)->update(['btn_title' => $values]);
        return true;
    }

    public static function updateStatus($id, $values)
    {
        DB::connection('sqlite')->table('bot_ads')->where('id', $id)->update(['status' => $values]);
        return true;
    }

    public static function updateBtnUrl($id, $values)
    {
        DB::connection('sqlite')->table('bot_ads')->where('id', $id)->update(['btn_url' => $values]);
        return true;
    }

    public static function RemoveAds($id)
    {
        return DB::connection('sqlite')->table('bot_ads')->where('id', $id)->delete();
    }
}
