import java.net.MalformedURLException;
import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import util.Log;

import map.data.City;
import map.store.ChainStore;

/**
 * サークルＫの店舗情報を取得します。
 * @author Masayasu Fujiwara
 */
public class SunkusPlugin extends ChainStore {

	/**
	 * 住所切り出しパターン
	 */
	private final Pattern ADDRESS_PARSER;

	public SunkusPlugin() {
		super("サンクス");
		this.ADDRESS_PARSER = Pattern.compile("<td width=\"296\" bgcolor=\"#FFFFFF\" class=\"text12\">([^<>]+)</td>");
	}

	@Override
	protected URL getURL(City city, int page) {
		URL url = null;
		try {
			url = new URL("http://sp.chizumaru.com/dbh/200080/list.aspx?account=200080&accmd=0&arg=&c1=2&c2=&c3=&c4=&c5=&c6=&c7=&c8=&c9=&c10=&c11=&c12=&c13=&c14=&c15=&c16=&c17=&c18=&c19=&c20=&c21=&c22=&c23=&c24=&c25=&c26=&c27=&c28=&c29=&c30=&pg="+ page +"&adr=" + City.cityFormat(city.getCode()));
		} catch (MalformedURLException e) {
			Log.err(this, e);
		}
		return url;
	}

	@Override
	protected String parseAddress(String input) {
		Matcher matcher = this.ADDRESS_PARSER.matcher(input);
		if (matcher.find()) {
			return matcher.group(1);
		}
		return null;
	}
}
