<?php

require_once('Model/Queries.php');
require_once('Model/Constant.php');
require_once('Utility/Utility.php');
require_once('Object/DataObject.php');
require_once('Object/ResponseObject.php');
require_once('QueryBuilder/QueryDecorator.php');
require_once('QueryBuilder/CustomQuery.php');
require_once('../../config.php');

class About extends Constant implements Queries
{
    private $dtObject;
    private $actionType = "";
    private $functionalityType = "";
    public $postData = [];


    function __construct(DataObject $dtObject)
    {

        parent::__construct();
        $this->dtObject = $dtObject;
        $this->actionType = $dtObject->getActionType();
        $this->functionalityType = $dtObject->getFunctionalityType();
        $this->postData = $dtObject->getPostData();


    }

    public function create(){
        $listOfData = [];
        $postdata = $this->postData;
//        Utility::DebugObject($postdata);
        if ($this->functionalityType == "insert_about_us") {
            $subjectname = "About Us";
            $Detail = isEmpty($postdata['ckeditor']);

            $queryDecorator = new QueryDecorator("INSERT INTO AboutUs(subject,detail)VALUES('$subjectname','$Detail')", new CustomQuery("0", ""));

            $result = queryRunner($queryDecorator->getQuery());
            if ($result != null) {
                session_start();
                header("location:../admin_panel/index.php");

            }

            return $this->getResponseObject("202", "Data insert Successfully", "1", "0", $listOfData);


        }
        else if ($this->functionalityType == "insert_Privacy_policy") {
            $subjectname = "Privacy Policy";
            $Detail = isEmpty($postdata['ckeditor']);

            $queryDecorator = new QueryDecorator("INSERT INTO PrivacyPolicy(subject,detail)VALUES('$subjectname','$Detail')", new CustomQuery("0", ""));

            $result = queryRunner($queryDecorator->getQuery());
            if ($result != null) {
                session_start();
                header("location:../admin_panel/index.php");

            }

            return $this->getResponseObject("202", "Data insert Successfully", "1", "0", $listOfData);


        }

    }

    public function retrieve(){
        $listOfData = [];
        $queryDecorator = new QueryDecorator("SELECT * FROM Brand",new CustomQuery("0",""));
        // $queryDecorator = new QueryDecorator("SELECT * FROM Brand",new CustomQuery("1","{select Count(*) from brand where id = '1'} as itemCount, "));
        // $queryDecorator = new QueryDecorator($queryDecorator->getQuery(),new CustomQuery("0"," WHERE id = '1' "));

        Utility::Logger($queryDecorator->getQuery());
        return $this->getResponseObject("202","Data Retrieve Successfully","1","0",$listOfData);
    }

    public function update(){



    }

    public function delete(){



    }

}