<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class OPD extends Model
{
    protected $table = 'opds';

    protected $fillable = [
        'name',
        'code',
        'description',
        'is_active',
    ];

    protected $casts = [
        'is_active' => 'boolean',
    ];

    public function responses()
    {
        return $this->hasMany(Response::class, 'opd_id');
    }

    public function getAverageRatingAttribute()
    {
        return $this->responses()->avg('rating') ?? 0;
    }
}

