<?php

namespace auctionforge\ajax\abs;

abstract class AjaxHandler {

    protected $BIDSPIRIT_API_BASE = "https://web2-qa.bidspirit.com/api/thirdparty/v1/";
    protected $action;
    protected $LANG = "he";

    public function __construct() {}

    public function init($action_name) {
        $this->init_hooks($action_name);
    }

    public function init_hooks($action_name) {
        add_action('wp_ajax_'.$action_name, array($this,'callback'));
        add_action('wp_ajax_nopriv_'.$action_name, array($this,'callback_nopriv'));
    }

    public function callback_nopriv() {
        $this->callback();
    }

    abstract public function callback();

    /**
     * @return string
     */
    public function getBidspiritAPIBase()
    {
        return $this->BIDSPIRIT_API_BASE;
    }

    /**
     * @return string
     */
    public function getLang()
    {
        return $this->LANG;
    }

    /**
     * @return string
     */
    public function getAction()
    {
        return $this->action;
    }

    /**
     * @param string $action
     */
    public function setAction($action)
    {
        $this->action = $action . ".api";
    }
}