<?php namespace Config;

class Validation
{
	//--------------------------------------------------------------------
	// Setup
	//--------------------------------------------------------------------

	/**
	 * Stores the classes that contain the
	 * rules that are available.
	 *
	 * @var array
	 */
	public $ruleSets = [
		\CodeIgniter\Validation\Rules::class,
		\CodeIgniter\Validation\FormatRules::class,
		\CodeIgniter\Validation\FileRules::class,
		\CodeIgniter\Validation\CreditCardRules::class,
	];

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

	# S: Hendi
	//--------------------------------------------------------------------
	// Login
	//--------------------------------------------------------------------
	public $login = [
		'user_id' => ['label' => 'Username', 'rules' => 'trim|required'],
		'password' => ['label' => 'Password', 'rules' => 'trim|required']  //|min_length[6]
	];
	public $login_errors = [
		'user_id' => [
			'required' => 'Username harus diisi',
		],
		'password' => [
			'required' => 'Password harus diisi',
			'min_length' => 'Password minimal 6 karakter',
		]
	];
	//--------------------------------------------------------------------
	// Menu
	//--------------------------------------------------------------------
	# created 24 jan 2021
    # updated 5 apr 2021
	# is_unique = Checks if this field value exists in the database. 
	# menu = table menu, slug = field slug.
	# Penggunaan is_unique[menu.slug, menu_id, {menu_id}]']
	# bahwa slug harus unik dalam database, 
	# kecuali untuk row yang memiliki menu_id yang cocok dengan nilai {menu_id}. 
	# ini berfungsi untuk edit database
	# jika tidak hanya is_unique[menu.slug], berjalan saat simpan tambah data tapi akan error saat simpan edit data.
    # alpha_numeric, agar cuma huruf dan angka saja yg diizinkan untuk menu_id
	public $menu = [
        'menu_id' => ['label' => 'Kode', 'rules' => 'trim|required|max_length[4]|alpha_numeric'],
		'menu_name' => ['label' => 'Nama Menu', 'rules' => 'trim|required|max_length[50]'],
		'slug' => ['label' => 'Slug', 'rules' => 'trim|required|max_length[50]'], #|is_unique[menu.slug, menu_id, {menu_id}] tidak jalan saat edit
        'unit' => ['label' => 'Satuan', 'rules' => 'trim|max_length[20]'],
        'price' => ['label' => 'Harga', 'rules' => 'trim|required|max_length[12]|numeric'],
		'description' => ['label' => 'Keterangan', 'rules' => 'trim|max_length[200]']  
	];
	public $menu_errors = [
        'menu_id' => [
			'required' => 'Kode harus diisi',
			'max_length' => 'Kode maksimal 4 karakter',
			'alpha_numeric' => 'Kode tidak valid'
		],
		'menu_name' => [
			'required' => 'Nama Menu harus diisi',
			'max_length' => 'Nama Menu maksimal 50 karakter',
		],
		'slug' => [
			'required' => 'Slug harus diisi',
			'max_length' => 'Slug maksimal 50 karakter',
			//'is_unique' => 'Nama Menu tersebut sudah digunakan'
		],
        'unit' => [
			'required' => 'Satuan harus diisi',
			'max_length' => 'Satuan maksimal 20 karakter',
		],
        'price' => [
			'required' => 'Harga harus diisi',
			'max_length' => 'Harga maksimal 12 karakter',
			'numeric' => 'Harga tidak valid'
		],
		'description' => [
			'required'      => 'Keterangan harus diisi',
			'max_length'    => 'Keterangan maksimal 200 karakter',
		]
	];
    //--------------------------------------------------------------------
	// Transaksi
	//--------------------------------------------------------------------
	# created 10 Apr 2021
	# is_unique = Checks if this field value exists in the database. 
	# transaction = table transaction
	# numeric, agar cuma angka saja yg diizinkan 
	public $transaksi = [
		'date' => ['label' => 'Tgl. Transaksi', 'rules' => 'trim|required'],
		'total' => ['label' => 'Total', 'rules' => 'trim|required|max_length[12]|numeric'],
        'tax' => ['label' => 'Pajak', 'rules' => 'trim|required|max_length[12]|numeric'],
        'total_paid' => ['label' => 'Total Bayar', 'rules' => 'trim|required|max_length[12]|numeric'],
        'cash' => ['label' => 'Uang Bayar', 'rules' => 'trim|required|max_length[12]|numeric'],
        'change' => ['label' => 'Kembali', 'rules' => 'trim|max_length[12]|numeric'],
        'note' => ['label' => 'Catatan', 'rules' => 'trim|max_length[200]']
	];
	public $transaksi_errors = [
		'date' => [
			'required' => 'Tgl. Transaksi harus diisi',
		],
        'total' => [
			'required' => 'Total harus diisi',
			'max_length' => 'Total maksimal 12 karakter',
			'numeric' => 'Total tidak valid'
		],
        'tax' => [
			'required' => 'Pajak harus diisi',
			'max_length' => 'Pajak maksimal 12 karakter',
			'numeric' => 'Pajak tidak valid'
		],
        'total_paid' => [
			'required' => 'Total Bayar harus diisi',
			'max_length' => 'Total Bayar maksimal 12 karakter',
			'numeric' => 'Total Bayar tidak valid'
		],
        'cash' => [
			'required' => 'Uang Bayar harus diisi',
			'max_length' => 'Uang Bayar maksimal 12 karakter',
			'numeric' => 'Uang Bayar tidak valid'
		],
        'change' => [
			'max_length' => 'Kembali maksimal 12 karakter',
			'numeric' => 'Kembali tidak valid'
		],
		'note' => [
			'max_length'    => 'Catatan maksimal 200 karakter',
		]
	];
	//--------------------------------------------------------------------
	// Antrian
	//--------------------------------------------------------------------
	# created 13 Apr 2021
	# is_unique = Checks if this field value exists in the database. 
	# antrian = table antrian
	# numeric, agar cuma angka saja yg diizinkan 
	public $antrian = [
		'queue_number' => ['label' => 'No Antrian', 'rules' => 'trim|required|max_length[6]|numeric'],
	];
	public $antrian_errors = [
		'queue_number' => [
			'required' => 'No Antrian harus diisi',
			'max_length' => 'No Antrian maksimal 6 karakter',
			'numeric' => 'No Antrian tidak valid'
		],
	];
	//--------------------------------------------------------------------
	// User
	//--------------------------------------------------------------------
	# created 11 Feb 2021
    # updated 6 Apr 2021
	# is_unique = Checks if this field value exists in the database. 
	# m_user = table m_user, user_id = field user_id.
	# Penggunaan is_unique[m_user.user_id, user_id, {user_id}]']
	# bahwa slug harus unik dalam database, 
	# kecuali untuk row yang memiliki user_id yang cocok dengan nilai {user_id}. 
	# ini berfungsi untuk edit database
	# jika tidak hanya is_unique[m_user.user_id], berjalan saat simpan tambah data tapi akan error saat simpan edit data.
	# alpha_numeric, agar cuma huruf dan angka saja yg diizinkan untuk user_id
	public $user = [
		'user_id' => ['label' => 'User ID', 'rules' => 'trim|required|max_length[20]|alpha_numeric'],
		'full_name' => ['label' => 'Nama Lengkap', 'rules' => 'trim|required|max_length[50]'],
		'level_id' => ['label' => 'Level', 'rules' => 'trim|required'],
        'description' => ['label' => 'Keterangan', 'rules' => 'trim|max_length[50]']
	];
	public $user_errors = [
		'user_id' => [
			'required' => 'User ID harus diisi',
			'max_length' => 'User ID maksimal 20 karakter',
			'alpha_numeric' => 'User ID tidak valid'
		],
		'full_name' => [
			'required' => 'Nama Lengkap harus diisi',
			'max_length' => 'Nama Lengkap maksimal 50 karakter',
		],
		'level_id' => [
			'required' => 'Level harus diisi'
		],
        'description' => [
			'max_length'    => 'Keterangan maksimal 50 karakter'
		]
	];
	//--------------------------------------------------------------------
	// Ubah Password
	//--------------------------------------------------------------------
	# created 11 feb 2021
	public $change_password = [
		'password' => ['label' => 'Password', 'rules' => 'trim|required|max_length[15]'],
		'new_password' => ['label' => 'Password Baru', 'rules' => 'trim|required|max_length[15]'],
		'confirm_password' => ['label' => 'Konfirmasi Password', 'rules' => 'trim|required|max_length[15]|matches[new_password]']
	];
	public $change_password_errors = [
		'password' => [
			'required' => 'Password Lama harus diisi',
			'max_length' => 'Password Lama maksimal 15 karakter',
		],
		'new_password' => [
			'required' => 'Password Baru harus diisi',
			'max_length' => 'Password Baru maksimal 15 karakter',
		],
		'confirm_password' => [
			'required' => 'Konfirmasi Password harus diisi',
			'max_length' => 'Konfirmasi Password maksimal 15 karakter',
			'matches' => 'Konfirmasi Password tidak sama',
		],
	];
	# E: Hendi
	//--------------------------------------------------------------------
	// Rules
	//--------------------------------------------------------------------
}
