<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Storage;

class ProjectFile extends Model
{
    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'id',
        // 'project_fileable_id',
        // 'project_fileable_type',
        'lat',
        'lng'
        // 'created_at',
        // 'updated_at'
    ];

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'path',
        'project_fileable_id',
        'project_fileable_type',
        'created_at',
        'updated_at'
    ];

    public $appends = ['full_path_for_fast_react'];

    /**
     * Get the owning project_fileable model.
     */
    public function project_fileable()
    {
        return $this->morphTo();
    }

    public function getFullPathForFastReactAttribute(){
        
        $path = Storage::disk('public')->url($this->path);
        $path = str_replace('public/', '', $path);
        return $path;
    }
    // public function getBeforeAttribute(){
    //     $path = Storage::disk('public')->url($this->path);
    //     $pos = strpos($path, 'before');
    //     if ($pos === false) {
    //         return 0;///// 0 before
    //     } else {
    //         return 1;////// 1 after
    //     }
    // }
    // public function getAfterAttribute(){
    //     $path = Storage::disk('public')->url($this->path);
    //     $pos = strpos($path, 'after');
    //     if ($pos === false) {
    //         return 0;///// 0 before
    //     } else {
    //         return 1;////// 1 after
    //     }
    // }
}
