<?php

namespace App\Models\Tenant;

use App\Models\Concerns\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphTo;

class WorkPhoto extends Model
{
    use BelongsToTenant;

    public const TYPES = [
        'defect' => 'Defect',
        'before' => 'Înainte',
        'after' => 'După',
        'general' => 'General',
    ];

    protected $fillable = [
        'company_id', 'work_order_id', 'subject_type', 'subject_id',
        'uploaded_by_id', 'path', 'type', 'caption', 'taken_at',
    ];

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

    public function subject(): MorphTo { return $this->morphTo(); }
    public function workOrder(): BelongsTo { return $this->belongsTo(WorkOrder::class); }
    public function uploadedBy(): BelongsTo { return $this->belongsTo(User::class, 'uploaded_by_id'); }

    public function url(): string
    {
        return \Illuminate\Support\Facades\Storage::url($this->path);
    }
}
