/* Copyright 2013 Akira Ohta (akohta001@gmail.com)
    This file is part of ntch.

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

    The ntch 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 General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with ntch.  If not, see <http://www.gnu.org/licenses/>.
    
*/
#ifndef _MODEL_2CH_H_
#define _MODEL_2CH_H_

#include "utils/nt_std_t.h"

typedef struct tag_nt_category_t *nt_category_tp;
typedef struct tag_nt_category_t{
	wchar_t *name;
	nt_link_tp boardlistp;
} nt_category_t;


typedef struct tag_nt_board_t *nt_board_tp;
typedef struct tag_nt_board_t{
	wchar_t *name;
	wchar_t *address;
	nt_link_tp threadlistp;
} nt_board_t;

typedef struct tag_nt_thread_t *nt_thread_tp;
typedef struct tag_nt_thread_t{
	wchar_t *name;
	wchar_t *file_name;
	int seq_no;
	int num_res;
	nt_link_tp reslistp;
} nt_thread_t;

typedef struct tag_nt_res_t *nt_res_tp;
typedef struct tag_nt_res_t{
	int seq_no;
	wchar_t *name;
	wchar_t *mail;
	wchar_t *misc;
	wchar_t *msg;
} nt_res_t;

typedef struct tag_nt_2ch_model_t *nt_2ch_model_tp;
typedef struct tag_nt_2ch_model_t{
	
	nt_link_tp categorylistp;
	
} nt_2ch_model_t;

typedef struct tag_nt_write_data_t *nt_write_data_tp;
typedef struct tag_nt_write_data_t
{
	char *name;
	char *mail;
	char *msg;
	wchar_t *status_msg;
	wchar_t *result_html;
	nt_link_tp cookies;
} nt_write_data_t;


typedef struct tag_nt_2ch_selected_item_t *nt_2ch_selected_item_tp;
typedef struct tag_nt_2ch_selected_item_t{
	nt_category_tp selected_categoryp;
	nt_board_tp selected_boardp;
	nt_thread_tp selected_threadp;
}nt_2ch_selected_item_t;


extern nt_write_data_tp nt_write_data_alloc();
extern void nt_write_data_free(nt_write_data_tp ptr);

extern nt_2ch_model_tp nt_2ch_model_alloc();
extern nt_category_tp nt_category_alloc(
		nt_2ch_model_tp modelp, const wchar_t *name);
extern nt_board_tp nt_board_alloc( nt_category_tp categoryp, 
		const wchar_t *name, const wchar_t *addressp);
extern nt_thread_tp nt_thread_alloc(
		nt_link_tp *threadlistpp, const wchar_t *name,
		const wchar_t *file_name, int num_res);
extern nt_res_tp nt_res_alloc(nt_thread_tp	threadp, 
		const wchar_t *name, const wchar_t *mail, 
		const wchar_t *misc, const wchar_t *msg);
extern nt_board_tp nt_get_board_by_name(
		nt_2ch_model_tp modelp, const wchar_t *board_name, nt_category_tp *categorypp);
extern nt_board_tp nt_get_board_by_address_match(
		nt_2ch_model_tp modelp, const wchar_t *param);
extern void nt_2ch_model_free(nt_2ch_model_tp ptr);
extern void nt_category_free(nt_category_tp ptr);
extern void nt_board_free(nt_board_tp ptr);
extern void nt_board_children_free(nt_board_tp ptr);
extern void nt_thread_free(nt_thread_tp ptr);
extern void nt_thread_children_free(nt_thread_tp ptr);
extern void nt_res_free(nt_res_tp ptr);

extern BOOL parse_board_menu(nt_2ch_model_tp modelp,
		const wchar_t *linep);
extern BOOL parse_board(nt_board_tp boardp, const wchar_t *linep);
extern BOOL parse_thread(nt_thread_tp boardp, const wchar_t *linep);

extern void nt_set_selected_board(nt_2ch_selected_item_tp selectp,
		nt_category_tp categoryp, nt_board_tp boardp);
extern void nt_set_selected_thread(
		nt_2ch_selected_item_tp selectp, nt_thread_tp threadp);

extern nt_thread_tp nt_get_thread_by_seq_no(
		nt_link_tp thread_list, int seq_no);
extern nt_thread_tp nt_get_thread_by_dat_name(
		nt_link_tp thread_list, const wchar_t *dat_name);
extern wchar_t* nt_read_thread_title(nt_board_tp boardp,
		const wchar_t *dat_name);
extern wchar_t* parse_thread_title(const wchar_t *linep);

#endif /* _MODEL_2CH_H_ */
