<?php

namespace Modules\VetClinic\Entities;

use Illuminate\Database\Eloquent\Model;
use App\Contact;

class VcPrescription extends Model
{
    protected $table = 'vc_prescriptions';
    protected $guarded = ['id'];

    protected $casts = [
        'prescribed_date' => 'date',
        'valid_until'     => 'date',
    ];

    public function owner()
    {
        return $this->belongsTo(Contact::class, 'contact_id');
    }

    public function pet()
    {
        return $this->belongsTo(VcPet::class, 'pet_id');
    }

    public function doctor()
    {
        return $this->belongsTo(VcDoctor::class, 'doctor_id');
    }

    public function appointment()
    {
        return $this->belongsTo(VcAppointment::class, 'appointment_id');
    }

    public function items()
    {
        return $this->hasMany(VcPrescriptionItem::class, 'prescription_id');
    }
}
