#include <assert.h>
#include "log.h"
#include "area_business.h"
#include "area_business_car_attendance.h"
#include "area_business_card_enter_or_leave.h"
#include "area_business_count_checker.h"
#include "area_business_forbid.h"
#include "area_business_person_dwell_checker.h"
#include "area_business_person_attendance.h"
#include "area_business_post_area.h"
#include "area_business_speed_checker.h"
#include "area_business_motionless_persion.h"
#include "area_business_geofault.h"
#include "area_business_work_rate.h"

struct area_business_factory
{
	void regist(int type,area_business* ab)
	{
		ab->m_business_type=type;

		if(type>=(int)m_check_list.size())
		{
			m_check_list.resize(type+1);
		}

		assert(!m_check_list[type]);
		m_check_list[type].reset(ab);
	}

	std::vector<area_business*> get_check_list(int business_type,int area_id)
	{
		std::vector<area_business*> check_list;
		for(int i=0;i<32;i++)
		{
			if(business_type==0)
				break;

			if((business_type&1)==0)
			{
				business_type >>= 1;
				continue;
			}

			business_type >>= 1;

			if(!m_check_list[i])
			{
				log_error("区域业务项目不存在:%d,area_id=%d",i,area_id);
				continue;
			}

			check_list.push_back(m_check_list[i].get());
		}

		return std::move(check_list);
	}

	static area_business_factory& instance()
	{
		static area_business_factory _instance;
		return _instance;
	}
	private:
	std::vector<std::unique_ptr<area_business>> m_check_list;
	area_business_factory()
	{
		regist(0, new area_business_post_area);
		regist(1, new area_business_person_dwell_checker);
		regist(2, new area_business_count_checker);
		regist(3, new area_business_speed_checker);
		regist(4, new area_business_person_attendance);
		regist(5, new area_business_car_attendance);
		regist(6, new area_business_forbid);
		regist(7, new area_business_card_enter_or_leave);
		regist(8, new area_business_motionless_persion);
		regist(9, new area_business_geofault);
		regist(10,new area_business_work_rate);
	}

};

std::vector<area_business*> area_business::get_instance_list(int business_type,int area_id)
{
	return area_business_factory::instance().get_check_list(business_type,area_id);
}