<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

use App\Traits\ScopeActive;

class Domain extends Model
{
	use HasFactory,ScopeActive;

	/* SCOPES */

	/**
	 * Only query active records
	 */
	public function scopePublic($query)
	{
		return $query->where('public',TRUE);
	}

	/* RELATIONS */

	public function echoareas()
	{
		return $this->hasMany(Echoarea::class);
	}

	public function fileareas()
	{
		return $this->hasMany(Filearea::class);
	}

	public function zones()
	{
		return $this->hasMany(Zone::class);
	}

	/* CASTS */

	public function getHomePageAttribute($value)
	{
		return $value ? gzuncompress(base64_decode($value)) : 'No available information at the moment.';
	}

	public function setHomePageAttribute($value)
	{
		$this->attributes['homepage'] = base64_encode(gzcompress($value,9));
	}
}