<?php

namespace App\Models_v2;

use Illuminate\Database\Eloquent\Model;

class Attachment extends Model {
	//
	protected $table = 'message_attachment_find_hostels';

	protected $fillable = [
		'message_id',
		'type',
		'image',
		'image_width',
		'image_height',
		'video',
		'video_duration',
		'video_thumbnail',
		'audio',
		'audio_duration'
	];

	public function thumbnail() {
		$type = $this->attributes['type'];
		if ( $type == 'image' ) {
			return '/files/'.$this->attributes['image'];
		}

		if ( $type == 'video' ) {
			return '/files/'.$this->attributes['video_thumbnail'];
		}

		return null;
	}

	public function height() {
		$type = $this->attributes['type'];
		if ( $type == 'image' ) {
			return $this->attributes['image_height'];
		}

		return null;
	}

	public function width() {
		$type = $this->attributes['type'];
		if ( $type == 'image' ) {
			return $this->attributes['image_width'];
		}

		return null;
	}

	public function duration() {
		$type = $this->attributes['type'];
		if ( $type == 'video' ) {
			return $this->attributes['video_duration'];
		}
		if ( $type == 'audio' ) {
			return $this->attributes['audio_duration'];
		}

		return null;
	}

	public function url() {
		$type = $this->attributes['type'];
		if ( $type == 'video' ) {
			return '/files/'.$this->attributes['video'];
		}
		if ( $type == 'audio' ) {
			return '/files/'.$this->attributes['audio'];
		}

		return '/files/'.$this->attributes['image'];
	}
}
