package com.yeejoin.amos.boot.module.jg.biz.edit.process.biz.vehicleInformation;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yeejoin.amos.boot.biz.common.entity.BaseEntity;
import com.yeejoin.amos.boot.module.jg.api.dto.FieldChangeMeta;
import com.yeejoin.amos.boot.module.jg.api.entity.JgVehicleInformation;
import com.yeejoin.amos.boot.module.jg.api.enums.BusinessTypeEnum;
import com.yeejoin.amos.boot.module.jg.biz.edit.core.RouterEventPublisher;
import com.yeejoin.amos.boot.module.jg.biz.edit.event.BaseBizDataChangeEvent;
import com.yeejoin.amos.boot.module.jg.biz.edit.process.biz.DefaultBizDataChangeHandler;
import com.yeejoin.amos.boot.module.ymt.api.enums.FlowStatusEnum;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 车用气瓶登记编辑处理器
 */
@Component
public class VehicleInformationDataChangeHandler extends DefaultBizDataChangeHandler<BaseBizDataChangeEvent> {

    private final VehicleInformationEditUpdateService vehicleInformationEditUpdateService;

    protected VehicleInformationDataChangeHandler(RouterEventPublisher routerEventPublisher, ApplicationContext applicationContext, VehicleInformationEditUpdateService vehicleInformationEditUpdateService) {
        super(routerEventPublisher, applicationContext);
        this.vehicleInformationEditUpdateService = vehicleInformationEditUpdateService;
    }

    @Override
    public String canHandleBizType() {
        return BusinessTypeEnum.JG_VEHICLE_GAS_APPLICATION.name();
    }

    @Override
    public List<FieldChangeMeta> updBizData(String bizId, String applyNo, ModelType model, Map<String, Object> changeData) {
        return Collections.emptyList();
    }

    @Override
    public Boolean beforeCheck(String bizId, String applyNo, ModelType model, Map<String, Object> changeData) {
        return Boolean.TRUE;
    }

    @Override
    public Set<String> getEqs(String applyNo) {
        return vehicleInformationEditUpdateService.getEqsByApplyNo(applyNo);
    }


    @Override
    public Boolean bizIsFinished(String applyNo) {
        JgVehicleInformation jgVehicleInformation = vehicleInformationEditUpdateService.getMainService().getOne(new LambdaQueryWrapper<JgVehicleInformation>().eq(JgVehicleInformation::getApplyNo, applyNo).select(BaseEntity::getSequenceNbr, JgVehicleInformation::getStatus));
        return jgVehicleInformation.getStatus().equals(FlowStatusEnum.TO_BE_FINISHED.getName());
    }

    @Override
    public Set<String> getProjectContraptionIds(String applyNo) {
        return Collections.emptySet();
    }
}
