<?php

namespace Config;

require_once APPPATH . 'Libraries/CustomValidations.php';

use CodeIgniter\Config\BaseConfig;
use CodeIgniter\Validation\StrictRules\CreditCardRules;
use CodeIgniter\Validation\StrictRules\FileRules;
use CodeIgniter\Validation\StrictRules\FormatRules;
use CodeIgniter\Validation\StrictRules\Rules;
use Libraries\CustomValidations;

class Validation extends BaseConfig
{
    // --------------------------------------------------------------------
    // Setup
    // --------------------------------------------------------------------

    /**
     * Stores the classes that contain the
     * rules that are available.
     *
     * @var list<string>
     */
    public array $ruleSets = [
        Rules::class,
        FormatRules::class,
        FileRules::class,
        CreditCardRules::class,
        CustomValidations::class
    ];

    /**
     * Specifies the views that are used to display the
     * errors.
     *
     * @var array<string, string>
     */
    public array $templates = [
        'list'   => 'CodeIgniter\Validation\Views\list',
        'single' => 'CodeIgniter\Validation\Views\single',
    ];

    // --------------------------------------------------------------------
    // Rules
    // --------------------------------------------------------------------

    public $validateSignIn = [
		'username'  => 'required|alpha_numeric',
		'password'  => 'required|min_length[5]',
	];

	public $validateNetworkSettings = [
		'device_mode'          => ['label' => 'Device Model', 'rules' => 'required|is_natural'],
		'eth1_mode'            => ['label' => 'Eth1 Mode', 'rules' => 'required|is_natural|max_length[20]'],
		'eth1_ip_address'      => ['label' => 'Eth1 Ip Address', 'rules' => 'permit_empty|valid_ip|max_length[20]'],
		'eth1_subnet_mask'     => ['label' => 'Eth1 Subnet Mask', 'rules' => 'permit_empty|valid_ip|max_length[20]'],
		'eth1_default_gateway' => ['label' => 'Eth1 Default Gateway', 'rules' => 'permit_empty|valid_ip|max_length[20]'],
		'eth2_mode'            => ['label' => 'Eth2 Mode', 'rules' => 'required|is_natural|max_length[20]'],
		'eth2_ip_address'      => ['label' => 'Eth2 Ip Address', 'rules' => 'permit_empty|valid_ip|max_length[20]'],
		'eth2_subnet_mask'     => ['label' => 'Eth2 Subnet Mask', 'rules' => 'permit_empty|valid_ip|max_length[20]'],
		'eth2_default_gateway' => ['label' => 'Eth2 Default Gateway', 'rules' => 'permit_empty|valid_ip|max_length[20]']
	];

	public $validateComSettings = [
		'baud_rate'   => ['label' => 'Baud Rate', 'rules' => 'required|is_natural'],
        'data_bits'   => ['label' => 'Data Bits', 'rules' => 'required|is_natural'],
        'parity_bits' => ['label' => 'Parity Bits', 'rules' => 'required|is_natural'],
        'stop_bits'   => ['label' => 'Stop Bits', 'rules' => 'required|is_natural']
	];
	
    public $validateConverterComSettings = [
		'mode' => ['label' => 'Mode', 'rules' => 'required|alpha_numeric_punct_all']
	];

	public $validateSlaveDevice = [
        'slv_id'    => ['label' => 'Slave Id', 'rules' => 'required|is_natural'],
		'reg_add'   => ['label' => 'Register Address', 'rules' => 'required|alpha_numeric_space|max_length[50]'],
		'fun_code'  => ['label' => 'Function Code', 'rules' => 'required|alpha_numeric_space|max_length[20]'],
		'no_of_reg' => ['label' => 'Number of Register', 'rules' => 'required|is_natural|max_length[10]'],
		'slv_rd'    => ['label' => 'Read', 'rules' => 'required|alpha_numeric_space|max_length[20]'],
        'req_intv'  => ['label' => 'Request Interval', 'rules' => 'required|is_natural'],
		'data_type' => ['label' => 'Data Type', 'rules' => 'required|alpha_numeric_space[100]']
	];

    public $validateTcpIpettings = [
        'mode'               => ['label' => 'Mode', 'rules' => 'required|alpha_numeric_punct_all'],
		'ip_address'         => ['label' => 'Ip Address', 'rules' => 'required|valid_ip'],
		'subnet_mask'        => ['label' => 'Subnet Mask', 'rules' => 'required|valid_ip'],
		'default_gateway'    => ['label' => 'Default Gateway', 'rules' => 'required|valid_ip'],
        'port'               => ['label' => 'Data Bits', 'rules' => 'required|is_natural|max_length[5]'],
        'connection_timeout' => ['label' => 'Parity Bits', 'rules' => 'required|is_natural|max_length[5]'],
        'response_timeout'   => ['label' => 'Stop Bits', 'rules' => 'required|is_natural|max_length[5]']
	];
    
    public $validateSpanningTreeSettings = [
        'priority'       => ['label' => 'Priority', 'rules' => 'required|is_natural|max_length[5]'],
		'maximum_age'    => ['label' => 'Maximum Age', 'rules' => 'required|is_natural|max_length[3]'],
		'hello_time'     => ['label' => 'Hello Time', 'rules' => 'required|is_natural|max_length[3]'],
		'forward_delay'  => ['label' => 'Forward Delay', 'rules' => 'required|is_natural|max_length[3]'],
        'primary_port'   => ['label' => 'Primary Port', 'rules' => 'required|alpha_numeric_space|max_length[5]'],
        'secondary_port' => ['label' => 'Secondary Port', 'rules' => 'required|alpha_numeric_space|max_length[5]']
	];
}
