package org.dromara.mall.trade.service;

import java.util.Map;

/**
 * 秒杀订单处理Service接口
 * 提供秒杀订单创建、验证、库存管理等核心业务逻辑
 *
 * @author pengles
 */
public interface SeckillOrderService {

    /**
     * 验证秒杀活动是否可用
     *
     * @param seckillId 秒杀活动ID
     * @param quantity  购买数量
     * @return 验证结果信息（包含是否可用、错误信息等）
     */
    SeckillValidationResult validateSeckillActivity(Long seckillId, Integer quantity);

    /**
     * 验证秒杀限购
     *
     * @param seckillId 秒杀活动ID
     * @param userId    用户ID
     * @param skuId     SKU ID
     * @return 是否允许购买
     */
    Boolean validatePurchaseLimit(Long seckillId, Long userId, Long skuId);

    /**
     * 预扣秒杀库存
     *
     * @param seckillId 秒杀活动ID
     * @param quantity  购买数量
     * @return 是否成功
     */
    Boolean preDeductSeckillStock(Long seckillId, Integer quantity);

    /**
     * 恢复秒杀库存（订单取消时调用）
     *
     * @param seckillId 秒杀活动ID
     * @param quantity  恢复数量
     * @return 是否成功
     */
    Boolean restoreSeckillStock(Long seckillId, Integer quantity);

    /**
     * 获取秒杀价格
     *
     * @param seckillId 秒杀活动ID
     * @return 秒杀价（分）
     */
    Integer getSeckillPrice(Long seckillId);

    /**
     * 秒杀验证结果
     */
    class SeckillValidationResult {
        private Boolean valid;
        private String errorMessage;
        private Map<String, Object> data;

        public SeckillValidationResult(Boolean valid, String errorMessage) {
            this.valid = valid;
            this.errorMessage = errorMessage;
        }

        public SeckillValidationResult(Boolean valid, String errorMessage, Map<String, Object> data) {
            this.valid = valid;
            this.errorMessage = errorMessage;
            this.data = data;
        }

        public Boolean getValid() {
            return valid;
        }

        public void setValid(Boolean valid) {
            this.valid = valid;
        }

        public String getErrorMessage() {
            return errorMessage;
        }

        public void setErrorMessage(String errorMessage) {
            this.errorMessage = errorMessage;
        }

        public Map<String, Object> getData() {
            return data;
        }

        public void setData(Map<String, Object> data) {
            this.data = data;
        }
    }

}
