<?php

namespace App\Repositories\Eloquent;

use App\Models\Rating;
use App\Repositories\Interfaces\RatingRepositoryInterface;

class RatingRepository extends BaseRepository implements RatingRepositoryInterface
{

    /**
    * RatingRepository constructor.
    *
    * @param Rating $model
    */
    public function __construct(Rating $model)
    {
       parent::__construct($model);
    }

    public function getRatingsAndAve(int $professionalId)
    {
        return $this->model->selectRaw(
            'SUM(rate) as total_rate, COUNT(*) as total_review'
            )
            ->where('professional_id', $professionalId)
            ->groupBy('professional_id')
            ->first();
    }
}
