<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;


class PrescriptionOrderModel extends Model
{
    use HasFactory;
    protected $table = 'tbl_prescription_order';


    protected $fillable = [
        'uid',
        'p_image',
        'pay_type_id',
        'pay_methode',
        'order_date',
        'o_status',
        'status',
        'gen_status',
        'subtotal',
        'waiting_duration',
        'notify_time',
        'tax',
        'technicalInput',
        'managementInput',
        'materialInput',
        'total',
        'insurance_total',
        'ins_code',
        'ins_type',
        'ins_limit',
        'hospital',
        'department',
        'doctor_name',
        'created_by',


    ];

    public function user()
    {
        return $this->belongsTo(UserModel::class, 'uid');
    }

    public function line()
    {
        return LineModel::where('u_id', $this->uid)
            ->where('shop_id', $this->created_by)
            ->value('bot_id');
    }

    public function medicines()
    {
        return $this->belongsTo(OrderDetailsModel::class, 'p_id');
    }

    public function orderDetails(): HasMany
    {
        return $this->hasMany(OrderDetailsModel::class, 'p_id');
    }
}
