<?php

namespace Hura8\Components\Customer\AdminController;

use Hura8\Components\Customer\Model\CustomerGroupModel;
use Hura8\Components\Province\AdminController\AProvinceController;
use Hura8\System\Controller\aAdminEntityBaseController;


class ACustomerGroupController extends aAdminEntityBaseController
{
    /* @var  CustomerGroupModel $objCustomerGroupModel */
    protected $objCustomerGroupModel;

    public function __construct()
    {
        $this->objCustomerGroupModel = new CustomerGroupModel();
        parent::__construct($this->objCustomerGroupModel);
    }


    public function getAllGroup() {
        return $this->objCustomerGroupModel->getList(["numPerPage" => 1000]);
    }


    public function removeCustomer($customer_id, $group_id)
    {
        return $this->objCustomerGroupModel->removeCustomer($customer_id, $group_id);
    }


    public function addCustomer($customer_id, $group_id)
    {
        return $this->objCustomerGroupModel->addCustomer($customer_id, $group_id);
    }


    public function getTotalCustomer($group_id, array $condition = [])
    {
        return $this->objCustomerGroupModel->getTotalCustomer($group_id, $condition);
    }


    public function getListCustomer($group_id, array $condition = []) {

        $objProvinceController = new AProvinceController();

        return array_map(function ($item) use ($objProvinceController){

            $item['province_name'] = $objProvinceController->getProvinceName($item['province']);

            return $item;

        }, $this->objCustomerGroupModel->getListCustomer($group_id, $condition));
    }


    protected function deleteFileBeforeDeleteItem($item_id): bool
    {
        // TODO: Implement deleteFileBeforeDeleteItem() method.
        return true;
    }
}
