<?php

namespace App\Modules\Bookings;

use Illuminate\Support\Facades\Auth;

class Followup extends Task
{
    protected static $rules = [
        'title'       => 'required',
        'problem'     => 'required',
        'client_id'   => 'required',
        'client_type' => 'required',
        'severity_id' => 'required',
    ];

    /**
     * The "booting" method of the model.
     *
     * @return void
     */
    public static function boot()
    {
        parent::boot();

        // When a transaction is created we want to
        // update the created_by field
        static::creating(function ($model) {
            $model->type = 'followup';
            $model->created_by = Auth::user()->id;
            $model->updated_by = Auth::user()->id;
        });

        // When a transaction gets updated we want to know who
        // updated it
        static::updating(function ($model) {
            $model->updated_by = Auth::user()->id;
        });
    }

    /**
     * Restrict query to type followup.
     */
    public function scopeFollowup($query)
    {
        return $query->where('type', 'followup');
    }
}
