#pragma once

#include <SQLAPI.h>
#include <string>
#include <vector>
#include <libxl.h>
#include "StringCodeConverter.h"

using namespace libxl;
using namespace std;

// #pragma comment( lib, "user32.lib")
// #pragma comment( lib, "version.lib")
// #pragma comment( lib, "oleaut32.lib")
// #pragma comment( lib, "ole32.lib")
// #pragma comment( lib, "libxl.lib")

#ifdef _DEBUG
#pragma comment( lib, "sqlapisd.lib")
#else
#pragma comment( lib, "sqlapis.lib")
#endif

typedef struct
{
	std::string strPolicySerial;
	std::string strSalerCode;
    std::string strSalerName;
    std::string strSalerDeptCode;
    std::string strSalerDeptName;
	std::string strCustomerName;
	std::string strPlateSerial;
	std::string strFrameSerial;
	std::string strEngineSerial;
	std::string strOperatorDate;
	std::string strOperatorCode;
    bool bIsAutotraderCall;
} SPolicyRecord;

typedef struct
{
	std::string strPolicySerial;
	std::string strSalerCode;
	std::string strPlateSerial;
	std::string strFrameSerial;
	std::string strEngineSerial;
	std::string strStartDate;
	std::string strEndDate;
} SPolicyQuery;

class TelSalePolicyGift
{
public:
    TelSalePolicyGift() {};
    TelSalePolicyGift( int id, string & name, string & defaultPrice ) : m_id( id ), m_giftName( name ), m_giftDefaultPrice( defaultPrice ) {}

    int Id() const { return m_id; }
    void Id(int val) { m_id = val; }

    string GiftName() const { return m_giftName; }
    void GiftName(string val) { m_giftName = val; }

    string GiftDefaultPrice() const { return m_giftDefaultPrice; }
    void GiftDefaultPrice(string val) { m_giftDefaultPrice = val; }

private:
    int m_id;
    string m_giftName;
    string m_giftDefaultPrice;
    
};

class CTelSalePolicyManager
{
public:
	CTelSalePolicyManager(void);
	virtual ~CTelSalePolicyManager(void);

public:
	static void Query( SPolicyQuery &policy, std::vector<SPolicyRecord> &vPolicy );
	static void SavePolicy( const SPolicyRecord & policy, const vector<TelSalePolicyGift> giftList );
    static void SavePolicyGift( const string & strPolicyNo, const vector<TelSalePolicyGift> & giftsList );
	static void LoadFromExcelFile( const char *pcszFilePath, std::vector<SPolicyRecord> *pvPolicy );
};



std::string QueryOperatorName( std::string strOperatorCode );
void QueryOperatorInfo( const string & cstrOperatorCode,
                        string & strOperatorName,
                        string & strDeptCode,
                        string & strDeptName );

std::string getCellString( ISheetT<wchar_t> *pSheet, int iRowIndex, int iColIndex );

void queryTelsalePolicyGifts( vector<TelSalePolicyGift> &giftList );