export default {
    getProfile: state => state.user,
    isProfileLoaded: state => !!state.user.name,
    isAdm: (state) => {
        let roles = state.user.roles;

        if (!roles) {
            return false;
        }

        var isAdm = false;
        roles.forEach(function (role, index) {
            if (role.name === 'ADM') {
                isAdm = true;
                return;
            }
        });
        return isAdm;
    },
    isManagerSalesConsultant: state => {
        let roles = state.user.roles;

        if (!roles) {
            return false;
        }

        var isManagerSalesConsultant = false;
        roles.forEach(function (role, index) {
            if (role.name === 'ManagerSalesConsultant') {
                isManagerSalesConsultant = true;
                return;
            }
        });
        return isManagerSalesConsultant;
    },
    isAnalyst: state => {
        let roles = state.user.roles;

        if (!roles) {
            return false;
        }

        var isAnalyst = false;
        roles.forEach(function (role, index) {
            if (role.name === 'Analyst') {
                isAnalyst = true;
                return;
            }
        });
        return isAnalyst;
    },
    isMarketing: state => {
        let roles = state.user.roles;

        if (!roles) {
            return false;
        }

        var isMarketing = false;
        roles.forEach(function (role, index) {
            if (role.name === 'Marketing') {
                isMarketing = true;
                return;
            }
        });
        return isMarketing;
    },
    isProcessOrders: state => {
        let roles = state.user.roles;

        if (!roles) {
            return false;
        }

        var isProcessOrders = false;
        roles.forEach(function (role, index) {
            if (role.name === 'ProcessOrders') {
                isProcessOrders = true;
                return;
            }
        });
        return isProcessOrders;
    },
    isIntegration: state => {
        let roles = state.user.roles;

        if (!roles) {
            return false;
        }

        var isIntegration = false;
        roles.forEach(function (role, index) {
            if (role.name === 'Integration') {
                isIntegration = true;
                return;
            }
        });
        return isIntegration;
    },
    isPromoter: state => {
        let roles = state.user.roles;

        if (!roles) {
            return false;
        }

        var isPromoter = false;
        roles.forEach(function (role, index) {
            if (role.name === 'Promoter') {
                isPromoter = true;
                return;
            }
        });

        if(state.user.sales_consultant != null && !isPromoter){
            isPromoter = state.user.sales_consultant.is_promoter;
        }

        return isPromoter;
    },
    isSalesConsultant: state => {
        let roles = state.user.roles;

        if (!roles) {
            return false;
        }

        var isSalesConsultant = false;
        roles.forEach(function (role, index) {
            if (role.name === 'SalesConsultant') {
                isSalesConsultant = true;
                return;
            }
        });
        return isSalesConsultant;
    },
    isManagerComercial: state => {
        let roles = state.user.roles;

        if (!roles) {
            return false;
        }

        var isSalesConsultant = false;
        roles.forEach(function (role, index) {
            if (role.name === 'ManagerComercial') {
                isSalesConsultant = true;
                return;
            }
        });
        return isSalesConsultant;
    },
    isSAC: state => {
        let roles = state.user.roles;

        if (!roles) {
            return false;
        }

        var isSalesConsultant = false;
        roles.forEach(function (role, index) {
            if (role.name === 'SAC') {
                isSalesConsultant = true;
                return;
            }
        });
        return isSalesConsultant;
    }
}
