001package scpc.model;
002
003import java.math.BigDecimal;
004import javax.script.ScriptException;
005
006/**
007 * Promotion rule which could be applicable to shopping cart.
008 * <br>促眅規則
009 *
010 * @author Kent Yeh
011 * @param <T> type of real cart item.
012 */
013public interface IRule<T> {
014
015    /**
016     * Priority, the smaller the value the higher the priority.
017     * <br>優先順序,數值越小越優先
018     *
019     * @return priority of rules.
020     */
021    public int getPriority();
022
023    /**
024     * Detecting item whether is applicable to this rule or not.
025     * <br>購物車品項是否適用於此規則
026     *
027     * @param item object in shopping cart.
028     * @return
029     */
030    public boolean contains(IItem<T> item);
031
032    /**
033     * Determined iterable items if matched.
034     * <br>走訪購物車品項時決定是否觸發的公式
035     *
036     * @param item cart item
037     * @return true if item matched.
038     * @throws javax.script.ScriptException
039     */
040    public boolean isTriggered(SingleItem<T> item) throws ScriptException;
041
042    /**
043     * Whether this rule is a leaf rule or not.
044     * <br>是否為最未端規則
045     *
046     * @return true if this rule is terminal.
047     */
048    public boolean isLeaf();
049
050    /**
051     * Previous rule.
052     * <br>串連的前規則
053     *
054     * @return previus link rule;
055     */
056    public IChainRule<T> getPrevious();
057
058    /**
059     * 價格精度
060     *
061     * @return price number scale.
062     */
063    public int getPriceScale();
064
065    /**
066     * Increase one count of items that is applicable to this rule.
067     * <br>增加符合此規則的品項計次
068     *
069     * @return this rule
070     */
071    public IRule<T> containsCountInc();
072
073    /**
074     * 符合此規則的品項數量
075     *
076     * @return number of items that could applicable to this rule.
077     */
078    public int getContainsCount();
079
080    /**
081     * Increase the summary sale price of applicable items.
082     * <br>增加符合此規則的品項售價小計
083     *
084     * @param salePrice
085     * @return
086     */
087    public IRule<T> sumOfContainsSalePriceInc(BigDecimal salePrice);
088
089    /**
090     * 符合此規則的品項售價小計
091     *
092     * @return The summary sale price of applicable items.
093     */
094    public BigDecimal getSumOfContainsSalePrice();
095
096    /**
097     * Increase the summary original price of applicable items.
098     * <br>增加符合此規則的品項原價小計
099     *
100     * @param salePrice
101     * @return
102     */
103    public IRule<T> sumOfContainsOriginalPriceInc(BigDecimal salePrice);
104
105    /**
106     * 符合此規則的品項原價小計
107     *
108     * @return The summary original price of applicable items.
109     */
110    public BigDecimal getSumOfContainsOriginalPrice();
111
112    /**
113     * Increase the summary sale price of the same applicable items.
114     * <br>增加符合此規則的同品項物品售價小計
115     *
116     * @param saleprice
117     * @return this rule.
118     */
119    public IRule<T> sumOfSerialSalePriceInc(BigDecimal saleprice);
120
121    /**
122     * 符合此規則的同品項售價小計
123     *
124     * @return The summary sale price of the same applicable items.
125     */
126    public BigDecimal getSumOfSerialSalePrice();
127
128    /**
129     * Reset the summary sale price of the same applicable items.
130     *
131     * @return this rule.
132     */
133    public IRule<T> resetSumOfSerialSalePrice();
134
135    /**
136     * Increase the summary oringal price of the same applicable items.
137     * <br>增加符合此規則的同品項原價小計
138     *
139     * @param oriprice original price
140     * @return this rule
141     */
142    public IRule<T> sumOfSerialOriginalPriceInc(BigDecimal oriprice);
143
144    /**
145     * 符合此規則的同品項原價小計
146     *
147     * @return The summary oringal price of the same applicable items.
148     */
149    public BigDecimal getSumOfSerialOriginalPrice();
150
151    /**
152     * Reset the summary original price of the same applicable items.
153     *
154     * @return this rule
155     */
156    public IRule<T> resetSumOfSerialOriginalPrice();
157
158    /**
159     * Reset sumary price to zero <br>
160     * 重置所有價格累計為零
161     */
162    public void resetSumOfPrice();
163}