<?php

namespace KupShop\AdminBundle\Resources\upgrade;

class AdminPrivilegeUpgrade extends \UpgradeNew
{
    public function check_emailsPrivilege()
    {
        return \Settings::getDefault()->user_rights_version == 5;
    }

    /** Add OTH_EMAILS_EDIT privilege to users with OTH_SET_EDIT */
    public function upgrade_emailsPrivilege()
    {
        $settings = \Settings::getDefault();

        $this->addPrivilegeToPrivilegedAdmins('OTH_SET_EDIT', 'OTH_EMAILS_EDIT');

        $this->commitDataMigration(6);

        $this->upgradeOK();
    }

    public function check_mainStatPrivilege()
    {
        return \Settings::getDefault()->user_rights_version == 6;
    }

    /** Add MAIN_STAT privilege to users with STAT */
    public function upgrade_mainStatPrivilege()
    {
        $settings = \Settings::getDefault();

        $this->addPrivilegeToPrivilegedAdmins('STAT', 'MAIN_STAT');

        $this->commitDataMigration(7);

        $this->upgradeOK();
    }

    public function check_fileBrowserPrivilege()
    {
        return \Settings::getDefault()->user_rights_version == 7;
    }

    /** Add FILE_BROWSER_USE privilege to all users */
    public function upgrade_fileBrowserPrivilege()
    {
        $settings = \Settings::getDefault();

        $this->addPrivilegeToPrivilegedAdmins(null, 'FILE_BROWSER_USE');

        $this->commitDataMigration(8);

        $this->upgradeOK();
    }

    public function check_retProdSetsReclaAndWatchPrivilege()
    {
        return \Settings::getDefault()->user_rights_version == 12;
    }

    /** Add WATCHDOG, PRODUCTS_SETS, RETURN and RECLAMATIONS privilege to all users */
    public function upgrade_retProdSetsReclaAndWatchPrivilege()
    {
        $settings = \Settings::getDefault();

        $this->addPrivilegeToPrivilegedAdmins('ORDER_ADD', 'RETURNS');
        $this->addPrivilegeToPrivilegedAdmins('ORDER_ADD', 'RECLAMATIONS');
        $this->addPrivilegeToPrivilegedAdmins('PROD_ADD', 'PROD_SETCATEGORIES');
        $this->addPrivilegeToPrivilegedAdmins('ORDER_ADD', 'WATCHDOG');

        $this->commitDataMigration(13);

        $this->upgradeOK();
    }

    public function check_prodPriceBuyPrivilege(): bool
    {
        return $this->checkDataMigration(18);
    }

    /** Add PROD_PRICEBUY privilege to all users */
    public function upgrade_prodPriceBuyPrivilege(): void
    {
        $this->addPrivilegeToPrivilegedAdmins('PROD_ADD', 'PROD_PRICEBUY');

        $this->commitDataMigration(18);

        $this->upgradeOK();
    }

    public function check_NewAdminPrivileges(): bool
    {
        return $this->checkDataMigration(24);
    }

    /** Add new admin privileges */
    public function upgrade_NewAdminPrivileges(): void
    {
        $this->addPrivilegeToPrivilegedAdmins('PROD_ADD', 'PROD_COMMENT');
        $this->addPrivilegeToPrivilegedAdmins('PROD_ADD', 'CONVERTORS');
        $this->addPrivilegeToPrivilegedAdmins('ART_ADD', 'ART_COMMENT');
        $this->addPrivilegeToPrivilegedAdmins('ORDER_ADD', 'RESERVATION');
        $this->addPrivilegeToPrivilegedAdmins(null, 'DROPSHIPMENT');
        $this->addPrivilegeToPrivilegedAdmins(null, 'GLOBAL_DISCNT');

        $this->commitDataMigration(24);

        $this->upgradeOK();
    }

    public function check_ClientSectionAdminPrivileges(): bool
    {
        return $this->checkDataMigration(25);
    }

    /** Add `CLIENT_SECTION` admin privileges */
    public function upgrade_ClientSectionAdminPrivileges(): void
    {
        $this->addPrivilegeToPrivilegedAdmins(null, 'CLIENT_SECTION');

        $this->commitDataMigration(25);

        $this->upgradeOK();
    }

    public function check_NewAdmin2Privileges(): bool
    {
        return $this->checkDataMigration(29);
    }

    /** Add new admin privileges MODULOVNA, INFO_PANELS, RETURNS ...*/
    public function upgrade_NewAdmin2Privileges(): void
    {
        $this->addPrivilegeToPrivilegedAdmins(null, 'MODULOVNA');
        $this->addPrivilegeToPrivilegedAdmins('PROD_ADD', 'VARIANT_LABELS');
        $this->addPrivilegeToPrivilegedAdmins('PROD_ADD', 'PRODUCT_TEMPLATES');
        $this->addPrivilegeToPrivilegedAdmins('PROD_ADD', 'CHARGES');
        $this->addPrivilegeToPrivilegedAdmins('USR_ADD', 'USER_GROUPS');
        $this->addPrivilegeToPrivilegedAdmins('ORDER_ADD', 'PAYMENTS');
        $this->addPrivilegeToPrivilegedAdmins('ORDER_ADD', 'BALIKOBOT');
        $this->addPrivilegeToPrivilegedAdmins(null, 'LABELS');

        $this->commitDataMigration(29);

        $this->upgradeOK();
    }
}
