<?php

namespace App\Validation;

use Config\Validation;

class UserValidation extends Validation
{
    public $validateUserOnLogin = [
        'email' => [
            'rules' => 'required|valid_email|is_not_unique[tbl_user.email]',
            'errors' => [
                'required' => 'The email is required',
                'valid_email' => 'The email is invalid',
                'is_not_unique' => 'The email is not found'
            ]
        ],
        'password' => [
            'rules' => 'required',
            'errors' => [
                'required' => 'The password is required',
            ]
        ],
    ];
    public $validateUserOnForgotPassword = [
        'email' => [
            'rules' => 'required|valid_email|is_not_unique[tbl_user.email]',
            'errors' => [
                'required' => 'The email is required',
                'valid_email' => 'The email is invalid',
                'is_not_unique' => 'The email is not found'
            ]
        ],

    ];
    public $validateUserOnSetPassword = [
        'password' => [
            'rules' => 'required|min_length[8]|max_length[20]|is_password_strong[password]',
            'errors' => [
                'required' => 'The password is required',
                'min_length' => 'The password should be at least {param} characters',
                'max_length' => 'The password should not exceed {param} characters',
                'is_password_strong' => 'Password is weak'
            ]
        ],
        'password2' => [
            'rules' => 'required|matches[password]',
            'errors' => [
                'required' => 'The password is required',
                'matches' => 'New passwords should match',
            ]
        ],

    ];
    public $validateUserOnChangePassword = [
        'current_password' => [
            'rules' => 'required|correct_current_password[current_password]',
            'errors' => [
                'required' => 'The password is required',
                'correct_current_password' => 'The current password is not correct',
            ]
        ],
        'new_password' => [
            'rules' => 'required|min_length[8]|max_length[20]|is_password_strong[new_password]|differs[current_password]',
            'errors' => [
                'required' => 'The password is required',
                'min_length' => 'The password should be at least {param} characters',
                'max_length' => 'The password should not exceed {param} characters',
                'is_password_strong' => 'Password is weak',
                'differs' => 'New password and current password should be different',
            ]
        ],
        'confirm_password' => [
            'rules' => 'required|matches[new_password]',
            'errors' => [
                'required' => 'The password is required',
                'matches' => 'New passwords should match',
            ]
        ],

    ];
    public $validateUserOnCreation = [
        'first_name' => [
            'rules' => 'required',
            'errors' => [
                'required' => 'Please enter first name'
            ]
        ],
        'last_name' => [
            'rules' => 'required',
            'errors' => [
                'required' => 'Please enter first name'
            ]
        ],
        'role' => [
            'rules' => 'permit_empty|in_list[Admin,Non-Admin]',
            'errors' => [
                'in_list' => 'Role is invalid'
            ]
        ],

        'email' => [
            'rules' => 'required|valid_email|is_unique[tbl_user.email]',
            'errors' => [
                'required' => 'Please enter email',
                'is_unique' => 'Email {value} is available',
                'valid_email' => 'Please enter correct email address'
            ]
        ],
    ];
    public $validateUserOnUpdate = [
        'id' => 'required|integer',
        'first_name' => [
            'rules' => 'required',
            'errors' => [
                'required' => 'Please enter first name'
            ]
        ],
        'last_name' => [
            'rules' => 'required',
            'errors' => [
                'required' => 'Please enter first name'
            ]
        ],
        'role' => [
            'rules' => 'permit_empty|in_list[Admin,Non-Admin]',
            'errors' => [
                'in_list' => 'Role is invalid'
            ]
        ],

        'email' => [
            'rules' => 'required|valid_email|is_unique[tbl_user.email,id,{id}]',
            'errors' => [
                'required' => 'Please enter email',
                'is_unique' => 'Email {value} is available',
                'valid_email' => 'Please enter correct email address'
            ]
        ],
    ];
}
