<?php


class Mbe_Shipping_Helper_PackageProduct
{
    protected $_cvs_package_product_table_name  = 'mbe_shipping_standard_package_product';

    public function installCsvPackageProductTable()
    {

        $sql = "CREATE TABLE IF NOT EXISTS `" . _DB_PREFIX_ . $this->_cvs_package_product_table_name . "`(
                `id_mbeshippingpackageproduct` int(10) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
                `custom_package` tinyint(1) NULL,
                `single_parcel` tinyint(1) NULL,
                `product_sku` varchar(64) NOT NULL DEFAULT '',
                `package_code` varchar(50) NOT NULL DEFAULT '',                                
                UNIQUE KEY MBE_PKG_PROD_PACKAGE_PRODUCT_UNIQUE  (package_code, product_sku),
                UNIQUE KEY MBE_PKG_PROD_PRODUCT_SKU  (product_sku),
                KEY MBE_PKG_PROD_PACKAGE_CODE  (package_code))";
        $result = Db::getInstance()->execute($sql);
        return $result;
    }

    public function uninstallCsvPackageProductTable()
    {
        $sql = "DROP TABLE IF EXISTS `" . _DB_PREFIX_ . $this->_cvs_package_product_table_name . "`";
        $result = Db::getInstance()->execute($sql);
        return $result;
    }

    public function truncate()
    {
        $truncateSql = " TRUNCATE `" . _DB_PREFIX_ . $this->_cvs_package_product_table_name . "` ";
        $truncateResult = Db::getInstance()->execute($truncateSql);
        return $truncateResult;
    }

    public function insertCsvPackageProduct($custom_package, $single_parcel, $product_sku, $package_code)
    {
        $sql = "
                INSERT INTO `" . _DB_PREFIX_ . $this->_cvs_package_product_table_name . "` (
                    `custom_package`,`single_parcel`,`product_sku`,`package_code`
                ) 
                VALUES (
                    " . $custom_package . ",
                    " . $single_parcel . ",
                    '" . $product_sku . "',
                    '" . $package_code . "'                    
                );";


        $insertResult = Db::getInstance()->execute($sql);
        return $insertResult;
    }
}