<?php

namespace Modules\ClinicCore\Entities;

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

class ClcPrescription extends Model
{
    protected $table = 'clc_prescriptions';
    protected $guarded = ['id'];

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

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

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

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

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

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