<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class ClientsDivGroups extends Model
{

    const DEFAULT_CID = 1; // swanusa account

    public static function getCDivGroups()
    {
        return DB::select("SELECT * FROM t_clients_div_groups WHERE dlt is null;");
    }

    public static function getCDivGroupById($c_div_group_id)
    {
        return DB::select("SELECT * FROM t_clients_div_groups WHERE dlt is null AND id = ? LIMIT 1;", [$c_div_group_id]);
    }

    public static function getCDivGroupByName($name)
    {
        return DB::select("SELECT * FROM t_clients_div_groups WHERE dlt is null AND name = ? LIMIT 2;", [$name]);
    }

    public static function addCDivGroup($data)
    {
        $c_div_group_id = DB::table("t_clients_div_groups")->insertGetId($data);
        return $c_div_group_id;
    }

    public static function updateCDivGroup($c_div_group_id, $data)
    {
        return DB::table("t_clients_div_groups")->where("id", $c_div_group_id)->update($data);
    }

    public static function deleteCDivGroup($c_div_group_id)
    {
        return DB::table("t_clients_div_groups")->where("id", $c_div_group_id)->delete();
    }
}
