<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

/**
 * Class State
 * @package App
 */
class State extends Model
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'id',
        'name',
    ];

    const INACTIVE = 'inactive';
    const ACTIVE = 'active';
    const REPAIRING = 'repairing';
    const WRITTEN_OFF = 'written_off';

    const VALID_STATES = [
        self::INACTIVE,
        self::ACTIVE,
        self::REPAIRING,
        self::WRITTEN_OFF
    ];

    /**
     * @param $state
     * @return mixed
     */
    public static function getStateId($state) {
        // States are never supposed to be changed !
        $id = array_search($state, self::VALID_STATES);

        return $id === false ? null : ++$id;
    }
}
