package cn.net.caoyao.cpzshandset.service.bll;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import cn.net.caoyao.cpzshandset.bean.City;
import cn.net.caoyao.cpzshandset.db.dal.CityDal;

public class CityBll {
    private CityDal cityDal;

    public CityBll(Context context) {

        cityDal = new CityDal(context);
    }
    
    /**
     * 通过编码查询城市信息
     * @param cityCode
     * @return
     */
    public City queryCityByCode(int cityCode){
    	return cityDal.queryCityByCode(cityCode);
    }

    /**
     * 获取全国的省市名称
     *
     * @return
     */
    public List<City> queryProvince() {
        return cityDal.queryProvince();
    }


    /**
     * 通过省名称获取城市列表
     *
     * @param city
     * @return
     */
    public List<City> queryCityByProvince(City city) {
        if (isProvinceLevelCity(city.getProvinceName())) {
            List<City> cities = new ArrayList<City>();
            City city1 = new City();
            city1.setProvinceName(city.getProvinceName());
            city1.setCityName(city.getProvinceName());
            city1.setCityCode(city.getCityCode());
            cities.add(city1);
            return cities;
        }
        return cityDal.queryCityByProvince(city);
    }

    /**
     * 通过省市获取三级区信息
     *
     * @param city
     * @return
     */
    public List<City> queryCityByCity(City city) {

        if (isProvinceLevelCity(city.getProvinceName())) {
            return cityDal.queryCityWhenProvinceLevel(city);
        } else {
            return cityDal.queryCityByCity(city);
        }
    }

    /**
     * 判断是否是直辖市
     *
     * @param province
     * @return
     */
    private boolean isProvinceLevelCity(String province) {
        String citys = "香港,澳门,台湾,北京市,上海市,天津市,重庆市,";
        if (citys.contains(province + ",")) {
            return true;
        }
        return false;
    }


}
