<?php

namespace App\Models\Goliath;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

use App\Traits\Owned;

class ReportAwareness extends Model
{
    use SoftDeletes;
    use Owned;

    protected $table = 'report_awareness';

    protected $fillable = [
        'type',
        'status',
        'report_id',
        'organisation_id',
        'gbps',
        'mpps',
        'address'
    ];

    protected $casts = [
        'type' => 'string',
        'status' => 'string',
        'report_id' => 'integer',
        'organisation_id' => 'integer',
        'gbps' => 'float',
        'mpps' => 'float',
        'address' => 'string'
    ];

    public function scopeOrganisation($query, $organisation_id)
    {
        return $query->where('organisation_id', $organisation_id);
    }

    // Scopes
    public function scopePending($query)
    {
        return $query->where('status', 'pending');
    }

    public function scopeSent($query)
    {
        return $query->where('status', 'sent');
    }

    public function scopeStart($query)
    {
        return $query->where('type', 'start');
    }

    public function scopeFinish($query)
    {
        return $query->where('type', 'finish');
    }

    // Helper methods
    public function markAsSent()
    {
        $this->status = 'sent';
        return $this->save();
    }

    public function isPending()
    {
        return $this->status === 'pending';
    }

    public function isSent()
    {
        return $this->status === 'sent';
    }

    public function isStart()
    {
        return $this->type === 'start';
    }

    public function isFinish()
    {
        return $this->type === 'finish';
    }
}