<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasOne;

class Visit extends Model
{
    protected $fillable = [
        'mr_id',
        'visit_date',
        'mapped_doctor_id',
        'area_id_resolved',
        'confidence_score',
        'assignment_status',
        'flags',
        'geom_point',
        'import_batch_id',
        'staging_row_id',
    ];

    protected $casts = [
        'visit_date' => 'date',
        'flags' => 'array',
    ];

    public function mr(): BelongsTo
    {
        return $this->belongsTo(Mr::class, 'mr_id');
    }

    public function mappedDoctor(): BelongsTo
    {
        return $this->belongsTo(Doctor::class, 'mapped_doctor_id');
    }

    public function areaResolved(): BelongsTo
    {
        return $this->belongsTo(Area::class, 'area_id_resolved');
    }

    public function importBatch(): BelongsTo
    {
        return $this->belongsTo(ImportBatch::class);
    }

    public function stagingRow(): BelongsTo
    {
        return $this->belongsTo(VisitRawStaging::class, 'staging_row_id');
    }
}
