<?php

namespace ModulesGarden\HostingQuotaNotifications\App\Libs\HostingDuedates;

use \ModulesGarden\HostingQuotaNotifications\App\Models\HostingDuedates as HostingDuedatesModel;
use \ModulesGarden\HostingQuotaNotifications\Core\Models\Whmcs;


/**
 * Description of Manage
 *
 * @author Artur Pilch <artur.pi@modulesgarden.com>
 */
class Manage
{
    public static function deleteAllByServiceId($serviceId)
    {
        HostingDuedatesModel::where('hid', '=', $serviceId);
    }
    
    public static function insertUpdatedData($serviceId)
    {
        if(self::hostingIsAdded($serviceId))
        {
            return;
        }
        $hosting = Whmcs\Hosting::select('id', 'nextduedate')->where('id', '=', $serviceId)->get()->first();

        $hostingDueDate = new HostingDuedatesModel();
        $hostingDueDate->hid = $hosting->id;
        $hostingDueDate->duedate = $hosting->nextduedate;
        $hostingDueDate->save();

    }
    
    public static function hostingIsAdded($serviceId)
    {
        return HostingDuedatesModel::select('hid')->where('hid', '=', $serviceId)->value('hid');
    }

    public static function saveByFill($data)
    {
        $dueDatesModel = new HostingDuedatesModel();
        $dueDatesModel->fill($data);
        $dueDatesModel->save();
    }
}
