<?php

namespace App\Rules;

use Illuminate\Contracts\Validation\Rule;

use Maatwebsite\Excel\Facades\Excel;

class AccountChartsOfAccountRule implements Rule
{
    /**
     * Create a new rule instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Determine if the validation rule passes.
     *
     * @param  string  $attribute
     * @param  mixed  $value
     * @return bool
     */
    public function passes($attribute, $value)
    {
        try {
            // dd($attribute,$value);
            $data = Excel::toArray([], $value)[0];
            //
            $words = ['id','name', 'number','account_type_number','description','opening_balance','sub_account_id'];


            if ($data[0][0] == $words[0] && $data[0][1] == $words[1] && $data[0][2] == $words[2] && $data[0][3] == $words[3] && $data[0][4] == $words[4] && $data[0][5] == $words[5] && $data[0][6] == $words[6]  ) {
                return true;
            } else {
                return false;
            }
        } catch (\Exception $e) {
            return false;
        }
    }

    /**
     * Get the validation error message.
     *
     * @return string
     */
    public function message()
    {
       
        return 'There is some issue in your file format.';
    }
}
