<?php

namespace App\Repositories\Frontend;

use App\Models\Category;
use Illuminate\Support\Facades\DB;
use App\Exceptions\GeneralException;
use App\Repositories\BaseRepository;


/**
 * Class ServiceRepository.
 */
class ServiceRepository extends BaseRepository
{
    /**
     * @return string
     */
    public function model()
    {
        return Category::class;
    }

     /**
     * @param string $orderBy
     * @param string $sort
     *
     * @return mixed
     */
    public function getAll()
    {
        return $this->model
            ->orderBy('category_name', 'asc')
            ->get();
    }

    /**
     *
     * @return int
     */
    public function getAllCount() : int
    {
        return $this->model
            ->count();
    }
    
    /**
     * @param string $orderBy
     * @param string $sort
     *
     * @return mixed
     */
    public function getActive($orderBy = 'created_at', $sort = 'desc')
    {
        return $this->model
            ->active()
            ->orderBy($orderBy, $sort)
            ->get();
    }

    public function getCategoryIdByName($categoryName){
        return $this->model->
                where('category_name', $categoryName)
                ->first();
    }

     /**
     * @param string $orderBy
     * @param string $sort
     *
     * @return mixed
     */
    public function getAllById($id)
    {
        return $data = $this->model
            ->where('id',$id)
            ->orderBy('category_name', 'asc')
            ->first();
    }
}
