<?php

namespace App\Modules\Help\Services;

use App\Modules\Help\Models\Help;

class HelpService
{

    public static function getEnableHelpList(){
        return Help::where('is_enabled',1)->select('id','title','is_enabled','created_at','updated_at')->orderBy('created_at','desc')->get();
    }

    public static function getAllHelpList(array $where=[]){
        if($where){
            return Help::select('id','title','content','is_enabled','created_at','updated_at')->where($where)->orderBy('id')->paginate(20);
        }else{
            return Help::select('id','title','content','is_enabled','created_at','updated_at')->orderBy('id')->paginate(20);
        }
    }

    public static function updateHelp(int $id,array $data){
        return Help::where('id',$id)->update($data);
    }

    public static function enableHelpStatus(int $id,int $status){
        return self::updateHelp($id,['is_enabled'=>$status]);
    }

    public static function create($data){
        return Help::create($data);
    }

    public static function getById(int $id){
        return Help::where('id',$id)->select('id','title','content','is_enabled','created_at','updated_at')->first();
    }
}