Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
37935 amit 1
package com.spice.profitmandi.dao.enumuration.fofo;
2
 
3
import java.util.Collections;
4
import java.util.EnumSet;
5
import java.util.Set;
6
 
7
/**
8
 * Lifecycle of a partner store, the single source of truth for fofo_store.active / closed.
9
 * ACTIVE and PAUSED can log in; PAUSED cannot spend from the wallet. SUSPENDED (nearing closure) and CLOSED cannot
10
 * log in. CLOSED is permanent: revival of a closed partner creates a new store.
11
 */
12
public enum StoreStatus {
13
	ACTIVE(true, true),
14
	PAUSED(true, false),
15
	SUSPENDED(false, false),
16
	CLOSED(false, false);
17
 
18
	private final boolean login;
19
	private final boolean walletSpend;
20
 
21
	StoreStatus(boolean login, boolean walletSpend) {
22
		this.login = login;
23
		this.walletSpend = walletSpend;
24
	}
25
 
26
	/** Partner can log in, and the store counts as active everywhere active was used before. */
27
	public boolean canLogin() {
28
		return login;
29
	}
30
 
31
	/** Partner-initiated wallet debits are allowed. System, admin and cron debits ignore this. */
32
	public boolean canSpendWallet() {
33
		return walletSpend;
34
	}
35
 
36
	public Set<StoreStatus> nextStatuses() {
37
		switch (this) {
38
			case ACTIVE:
39
				return Collections.unmodifiableSet(EnumSet.of(PAUSED, SUSPENDED));
40
			case PAUSED:
41
				return Collections.unmodifiableSet(EnumSet.of(ACTIVE, SUSPENDED));
42
			case SUSPENDED:
43
				return Collections.unmodifiableSet(EnumSet.of(ACTIVE, PAUSED, CLOSED));
44
			default:
45
				return Collections.emptySet();
46
		}
47
	}
48
 
49
	public boolean canMoveTo(StoreStatus target) {
50
		return nextStatuses().contains(target);
51
	}
52
 
53
	public static StoreStatus fromFlags(boolean active, boolean closed) {
54
		return closed ? CLOSED : active ? ACTIVE : SUSPENDED;
55
	}
56
 
57
	public static Set<StoreStatus> loginStatuses() {
58
		return Collections.unmodifiableSet(EnumSet.of(ACTIVE, PAUSED));
59
	}
60
}