<?php

namespace App\Models;

use App\Helper\Util;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Attachment extends Model
{
    use SoftDeletes;

    public $table = 'attachments';

    protected $dates = ['deleted_at'];

    const INSTANCE_TYPE_PRODUCTION = "production";

    const INSTANCE_TYPE_SALES = "sales";
    const INSTANCE_TYPE_ADMIN = "admin";


    // public static $INSTANCE_TYPES = [
    //     self::INSTANCE_TYPE_PRODUCTS => "production",
    // ];


    public $fillable = [
        'path',
        'instance_type',
        'instance_id',

        'subtype',
        'name',
    ];

    /**
     * The attributes that should be casted to native types.
     *
     * @var array
     */
    protected $casts = [];

    /**
     * The objects that should be append to toArray.
     *
     * @var array
     */
    protected $with = [];

    /**
     * The attributes that should be append to toArray.
     *
     * @var array
     */
    protected $appends = [
        'attachment_url',
    ];

    /**
     * The attributes that should be visible in toArray.
     *
     * @var array
     */
    protected $visible = [
        "id",
        "name",
        "path",
        "instance_type",
        "instance_id",
        "created_at",
        "updated_at",
        "attachment_url",
    ];

    public function getAttachmentUrlAttribute()
    {
        return ($this->path && url('storage/app/' . $this->path)) ? url('storage/app/' . $this->path) : url('/storage/app/users/user.png');
    }


}
