Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.spice.profitmandi.dao.enumuration.fofo;

import java.util.Collections;
import java.util.EnumSet;
import java.util.Set;

/**
 * Lifecycle of a partner store, the single source of truth for fofo_store.active / closed.
 * ACTIVE and PAUSED can log in; PAUSED cannot spend from the wallet. SUSPENDED (nearing closure) and CLOSED cannot
 * log in. CLOSED is permanent: revival of a closed partner creates a new store.
 */
public enum StoreStatus {
        ACTIVE(true, true),
        PAUSED(true, false),
        SUSPENDED(false, false),
        CLOSED(false, false);

        private final boolean login;
        private final boolean walletSpend;

        StoreStatus(boolean login, boolean walletSpend) {
                this.login = login;
                this.walletSpend = walletSpend;
        }

        /** Partner can log in, and the store counts as active everywhere active was used before. */
        public boolean canLogin() {
                return login;
        }

        /** Partner-initiated wallet debits are allowed. System, admin and cron debits ignore this. */
        public boolean canSpendWallet() {
                return walletSpend;
        }

        public Set<StoreStatus> nextStatuses() {
                switch (this) {
                        case ACTIVE:
                                return Collections.unmodifiableSet(EnumSet.of(PAUSED, SUSPENDED));
                        case PAUSED:
                                return Collections.unmodifiableSet(EnumSet.of(ACTIVE, SUSPENDED));
                        case SUSPENDED:
                                return Collections.unmodifiableSet(EnumSet.of(ACTIVE, PAUSED, CLOSED));
                        default:
                                return Collections.emptySet();
                }
        }

        public boolean canMoveTo(StoreStatus target) {
                return nextStatuses().contains(target);
        }

        public static StoreStatus fromFlags(boolean active, boolean closed) {
                return closed ? CLOSED : active ? ACTIVE : SUSPENDED;
        }

        public static Set<StoreStatus> loginStatuses() {
                return Collections.unmodifiableSet(EnumSet.of(ACTIVE, PAUSED));
        }
}