<?php

namespace App\Models;
use App\Enums\RecordStatusEnum;
use App\Models\Traits\HasLocalizedName;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Support\Facades\Session;
use App\Traits\AuditLogTrait;

class Laboratory extends BaseModel
{
    public $timestamps = false;
    use HasFactory;
    use HasLocalizedName;
    use AuditLogTrait;
    /**
     * The table associated with the model.
     *
     * @var string
     */

    protected $appends = ['name'];

    protected $primaryKey = 'id';



    protected $fillable = [
        'name_en', 'name_kh', 'short_name', 'address_en', 'address_kh', 'sample_number', 'patient_code', 'is_hide_inv_discount',
        'verify_label', 'technician_label', 'logo', 'discount_type','currency', BaseModel::CREATED_AT_FIELD, 'start_date', 'end_date',
        'phone_number', 'email', 'shareable_lab_result','allow_external_request','telegrambot','exchange_rate','result_header_id','show_result_footer',
        'abnormal_result_font_weight','abnormal_text_color','is_hide_comission_percentage','invoice_template_id','alternative_logo','alter_verify_sign','alter_labtech_sign',
        'alternative_footer', 'footer', 'is_auto_make_invoice',
        BaseModel::CREATED_BY_FIELD, BaseModel::UPDATED_AT_FIELD, BaseModel::UPDATED_BY_FIELD, BaseModel::RECORD_STATUS_FIELD
    ];

    public static function boot()
    {
        parent::boot();
    }

    public function userLabCovers(){
        return $this->hasMany('App\Models\UserLabCover', 'lab_id','id')->where('record_status_id', RecordStatusEnum::ACTIVE);
    }

    public function labUsers(){
        return $this->hasMany('App\Models\UserLabCover', 'lab_id','id')->where('record_status_id', RecordStatusEnum::ACTIVE)->where('lab_id', Session::get('base_lab_id'));
    }

}
