<?php

namespace App\Models;

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

class AppointmentPhoto extends Model
{
    use HasFactory;

    protected $fillable = [
        'appointment_id',
        'barber_id',
        'file_path',
        'file_size_kb',
        'taken_at',
        'notes',
    ];

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

    protected $appends = ['url'];

    public function appointment()
    {
        return $this->belongsTo(Appointment::class);
    }

    public function barber()
    {
        return $this->belongsTo(Barber::class);
    }

    public function getUrlAttribute()
    {
        if (!$this->file_path) {
            return null;
        }
        return url('photos/' . $this->file_path);
    }
}
