<?php

namespace App\Rules;

use Illuminate\Contracts\Validation\Rule;

class PublishOn implements Rule
{
    protected $lang;

    public function __construct($lang = null)
    {
        $this->lang = $lang;
    }

    /**
     * Determine if the validation rule passes.
     *
     * @param  string  $attribute
     * @param  mixed  $value
     * @return bool
     */
    public function passes($attribute, $value)
    {
        // Bad stuff, don't do this at home
        if ($this->lang) {
            $status = request()->lang_status[$this->lang];
        } else {
            $status = request()->status;
        }

        return empty($value) || $status == 'draft';
    }

    /**
     * Get the validation error message.
     *
     * @return string
     */
    public function message()
    {
        return 'To establish a publish date the ' . ($this->lang ? 'Translation ' : '') . ' Status has to be Draft';
    }
}
