<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Camera extends Model
{
    protected $fillable = [
        'name', 'location', 'rtsp_url', 'snapshot_url',
        'username', 'password', 'chainage', 'highway',
        'latitude', 'longitude', 'notes', 'is_active',
    ];

    protected $casts = [
        'is_active' => 'boolean',
        'latitude'  => 'float',
        'longitude' => 'float',
    ];

    /** Returns a URL-safe RTSP string (masking password for display) */
    public function rtspDisplay(): string
    {
        $url = $this->rtsp_url;
        if ($this->password) {
            $url = preg_replace('/:([^@]+)@/', ':****@', $url);
        }
        return $url;
    }
}
