<?php

namespace App\Packages\Capsule\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Carbon;
use Ramsey\Uuid\Uuid;

/**
 * Class CapsulePreview
 * @package App\Packages\Capsule\Models
 *
 * @property int $id
 * @property string $uuid
 * @property string $size
 * @property string $hash
 * @property string $ext
 * @property string $width
 * @property string $height
 * @property string $mime_type
 * @property string $aws_key
 * @property string $aws_bucket
 *
 * @property string|Carbon $created_at
 * @property string|Carbon $updated_at
 * @property string|Carbon $deleted_at
 */
class CapsulePreview extends Model
{
    use SoftDeletes;

	/** @var string */
	protected $table = 'table_capsule_preview';

	/** @var string */
	public $fileContent;

	public static function boot()
	{
		parent::boot();
		static::creating(function ($model) {
			/** @var static $model */
			$model->uuid = Uuid::uuid4();
		});
	}

	/**
     * @return string
     *
     * @throws \Exception
     */
	public function generateName()
	{
		return Uuid::uuid4()->toString() . "." . $this->ext;
	}

    /**
     * Get full file path
     */
    public function getAwsFullPath()
    {
        return  env('AWS_URL') . '/' . env('AWS_PREVIEW_BUCKET') . '/' . $this->aws_key;
    }

	/**
	 * @return string
	 */
	public function getFullFileName()
	{
		return $this->uuid . '.' . $this->ext;
	}
}
