<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Ajax extends AJAX_Controller  {

    public function __construct()
    {
        parent::__construct();


    }



    public function add(){


        if(!GroupAccess::isGranted('coupons',ADD_COUPON)){
            echo json_encode(array(Tags::SUCCESS=>0,Tags::ERRORS=>array(
                "error"  => Translate::sprint(Messages::PERMISSION_LIMITED)
            )));
            exit();
        }

        $params = array(
            'user_id' => SessionManager::getData('id_user'),
            'store_id' => RequestInput::post("store_id"),
            'label' => RequestInput::post("label"),
            'coupon_value' => RequestInput::post("coupon_value"),
            'expired_at' => RequestInput::post("expired_at"),
            'linkedProducts' => RequestInput::post("linkedProducts")
        );

        echo json_encode(
            $this->mCouponsModel->add($params)
        );return;

    }



    public function delete(){


        if(!GroupAccess::isGranted('coupons',DELETE_COUPON)){
            echo json_encode(array(Tags::SUCCESS=>0,Tags::ERRORS=>array(
                "error"  => Translate::sprint(Messages::PERMISSION_LIMITED)
            )));
            exit();
        }

        echo json_encode(
            $this->mCouponsModel->delete(RequestInput::post("id") , SessionManager::getData('id_user'))
        );return;

    }



}