package com.cf.imes.module.system.service.customplateno.factory;

import com.cf.imes.framework.common.exception.ServiceException;
import com.cf.imes.module.system.enums.ErrorCodeConstants;
import com.cf.imes.module.system.enums.customplateno.CustomPlateNoRuleCodeEnum;
import com.cf.imes.module.system.service.customplateno.factory.service.AbstractCustomPlateNoResetServiceHandler;
import com.cf.imes.module.system.service.customplateno.factory.service.impl.BodyNoRuleResetServiceHandler;
import com.cf.imes.module.system.service.customplateno.factory.service.impl.OrderNoRuleResetServiceHandler;
import com.cf.imes.module.system.service.customplateno.factory.service.impl.PlateNoRuleResetServiceHandler;
import com.cf.imes.module.system.service.customplateno.factory.service.impl.RoomNoRuleResetServiceHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

/**
 * 自定义板编号规则复位处理器工厂类
 *
 * @author Gqr
 * @since 2024/11/28 16:21
 */
@Component
public class CustomPlateNoResetModeServiceFactory {
    private final ApplicationContext applicationContext;

    @Autowired
    public CustomPlateNoResetModeServiceFactory(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }

    /**
     * 根据复位模式获取对应的处理器
     *
     * @param roleCode
     * @return
     */
    public AbstractCustomPlateNoResetServiceHandler getResetServiceHandler(String roleCode) {
        CustomPlateNoRuleCodeEnum ruleCodeEnum = CustomPlateNoRuleCodeEnum.match(roleCode);
        switch (ruleCodeEnum) {
            case ORDERNO:
                return applicationContext.getBean(OrderNoRuleResetServiceHandler.class);
            case ROOMNO:
                return applicationContext.getBean(RoomNoRuleResetServiceHandler.class);
            case BODYNO:
                return applicationContext.getBean(BodyNoRuleResetServiceHandler.class);
            case PLATENO:
                return applicationContext.getBean(PlateNoRuleResetServiceHandler.class);
            default:
                throw new ServiceException(ErrorCodeConstants.SYSTEM_CONFIG_CUSTOM_PLATE_NO_RULE_RESET_NOT_SUPPORT);
        }
    }
}
