/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.parsers.vnts; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.dbs.*;
import gplx.xowa.langs.vnts.*;
class Vnt_log_mgr {		
	private int uid;
	private int page_id, rule_idx;
	private Xol_vnt_regy vnt_regy;
	private int[] vnt_ary = new int[10];
	private Vnt_log_tbl tbl;
	public void Init_by_db(Db_conn conn, Xol_vnt_regy vnt_regy) {
		this.vnt_regy = vnt_regy;
		this.tbl = new Vnt_log_tbl(conn);
		tbl.Create_tbl();
		this.uid = 0;
		this.page_id = 0;
	}
	public void Init_by_page(int page_id) {
		this.page_id = page_id;
		this.rule_idx = -1;
		for (int i = 0; i < 10; ++i)
			vnt_ary[i] = 0;
	}
	public void Log_lang(byte[] vnt, int scope) {Log_lang(vnt_regy.Get_by(vnt), scope);}
	public void Log_lang(Xol_vnt_itm itm, int scope) {
		int idx = itm.Idx();
		int val = vnt_ary[idx];
		vnt_ary[idx] = val == 0 ? scope : val | scope;
	}
	public void Log_rule(int src_bgn, int src_end, byte[] src_txt, Vnt_flag_code_mgr flag_codes, Vnt_flag_lang_mgr flag_langs, Vnt_rule_undi_mgr rule_undis, Vnt_rule_bidi_mgr rule_bidis) {
		tbl.Insert(uid, page_id, ++rule_idx
		, flag_codes.Count(), flag_langs.Count(), rule_undis.Len(), rule_bidis.Len()
		, flag_codes.Get(Vnt_flag_code_.Tid_add), flag_codes.Get(Vnt_flag_code_.Tid_del), flag_codes.Get(Vnt_flag_code_.Tid_aout), flag_codes.Get(Vnt_flag_code_.Tid_hide), flag_codes.Get(Vnt_flag_code_.Tid_raw), flag_codes.Get(Vnt_flag_code_.Tid_show), flag_codes.Get(Vnt_flag_code_.Tid_descrip), flag_codes.Get(Vnt_flag_code_.Tid_name), flag_codes.Get(Vnt_flag_code_.Tid_title), flag_codes.Get(Vnt_flag_code_.Tid_err)
		, vnt_ary[0], vnt_ary[1], vnt_ary[2], vnt_ary[3], vnt_ary[4], vnt_ary[5], vnt_ary[6], vnt_ary[7], vnt_ary[8], vnt_ary[9]
		, src_bgn, src_end, src_txt
		);
	}
	public void Rls() {
		tbl.Rls();
	}
	public static final int Scope__lang = 1, Scope__undi = 2, Scope__bidi = 4;
}
