<?php

namespace App\Models;

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

class Signalement extends Model
{
    use HasFactory;

    protected $fillable = [
        'mission_id', 'client_id', 'type_signalement', 'description',
        'gravite', 'statut', 'traite_par', 'resolution', 'date_resolution',
    ];

    protected $casts = [
        'date_resolution' => 'datetime',
    ];

    // Relations
    public function mission(): \Illuminate\Database\Eloquent\Relations\BelongsTo
    {
        return $this->belongsTo(Mission::class);
    }

    public function client(): \Illuminate\Database\Eloquent\Relations\BelongsTo
    {
        return $this->belongsTo(Client::class);
    }

    public function traitePar(): \Illuminate\Database\Eloquent\Relations\BelongsTo
    {
        return $this->belongsTo(User::class, 'traite_par');
    }

    // Scopes
    public function scopeDuClient(\Illuminate\Database\Eloquent\Builder $query, int $clientId): \Illuminate\Database\Eloquent\Builder
    {
        return $query->where('client_id', $clientId);
    }
}
