<?php

namespace App;

//use Illuminate\Auth\Authenticatable;
//use Illuminate\Database\Eloquent\Model;
//use Illuminate\Auth\Passwords\CanResetPassword;
//use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
//use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;

use SleepingOwl\Models\SleepingOwlModel;

use SleepingOwl\Models\Interfaces\ModelWithImageFieldsInterface;
use SleepingOwl\Models\Traits\ModelWithImageOrFileFieldsTrait;
use SleepingOwl\Models\Interfaces\ModelWithOrderFieldInterface;
use SleepingOwl\Models\Traits\ModelWithOrderFieldTrait;

use Intervention\Image\ImageManagerStatic as Image;

class Campaign 
        extends 
            SleepingOwlModel 
        implements 
            ModelWithOrderFieldInterface, 
            ModelWithImageFieldsInterface
{
    use ModelWithImageOrFileFieldsTrait;
    use ModelWithOrderFieldTrait;

    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'campaigns';

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
//    protected $fillable = ['description', 'heading'];
    protected $fillable = ['description', 'heading', 'info', 'image', 'sort', 'thumbnail'];

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = [];

    /**
     * Show a list of all available elements.
     *
     * @return Response
     */
//    public function index()
//    {
//        $articles = Article::all();
//
//        return view('article.index', ['articles' => $articles]);
//    }
    
    public function getSortField()
    {
        return 'sort';
    }
    
    public function getImageFields()
    {
        return [
            'image' => 'images/',
            'photo' => '',
            'other' => ['images/', function($directory, $originalName, $extension)
            {
                return $originalName;
            }]
        ];
    }
    
    public function setImage($field, $image)
    {
        parent::setImage($field, $image);
        $file = $this->$field;
        if (!$file->exists()) {
            return;
        }
        $path = $file->getFullPath();
        
    }
    
    public static function getList() {
        return static::lists('heading', 'id')->toArray();
    }
   
}
