<?php

namespace App\Models;

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

class Diagnosis extends Model
{
    use HasFactory;

    protected $fillable = [
        'job_card_id',
        'service_coordinator_id',
        'customer_reported_issues',
        'diagnostic_findings',
        'root_cause_analysis',
        'recommended_repairs',
        'additional_issues_found',
        'priority_level',
        'estimated_repair_time',
        'diagnosis_status',
        'diagnosis_date',
        'photos',
        'diagnostic_codes',
        'test_results',
        'parts_required',
        'labor_operations',
        'special_tools_required',
        'safety_concerns',
        'environmental_impact',
        'customer_authorization_required',
        'notes',
    ];

    protected $casts = [
        'diagnosis_date' => 'datetime',
        'photos' => 'array',
        'diagnostic_codes' => 'array',
        'test_results' => 'array',
        'parts_required' => 'array',
        'labor_operations' => 'array',
        'special_tools_required' => 'array',
        'customer_authorization_required' => 'boolean',
    ];

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

    public function serviceCoordinator(): BelongsTo
    {
        return $this->belongsTo(User::class, 'service_coordinator_id');
    }

    public function estimate(): HasOne
    {
        return $this->hasOne(Estimate::class);
    }

    public function timesheets(): HasMany
    {
        return $this->hasMany(Timesheet::class);
    }
}
