package com.yeejoin.amos.boot.module.jg.biz.reminder.biz.newEquip;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.module.jg.api.enums.BusinessTypeEnum;
import com.yeejoin.amos.boot.module.jg.biz.reminder.core.DefaultReminder;
import com.yeejoin.amos.boot.module.jg.biz.reminder.dto.MatchItemDto;
import com.yeejoin.amos.boot.module.jg.biz.reminder.dto.ReminderItemDto;
import com.yeejoin.amos.boot.module.ymt.api.entity.IdxBizJgRegisterInfo;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.Map;

@Component

public class NewEquipReminderAdapter extends DefaultReminder {

    private final NewEquipParseService newEquipParseService;

    public NewEquipReminderAdapter(ApplicationContext applicationContext, NewEquipParseService newEquipParseService) {
        super(applicationContext);
        this.newEquipParseService = newEquipParseService;
    }

    @Override
    public IPage<ReminderItemDto> realtimeParse(String bizId, Page<ReminderItemDto> page) {
        IdxBizJgRegisterInfo registerInfo = newEquipParseService.getIdxBizJgRegisterInfoService().getOneData(bizId);
        ReminderItemDto reminderItemDto = new ReminderItemDto();
        reminderItemDto.setEquipId(bizId);
        reminderItemDto.setEquipNo(registerInfo.getEquCode());
        reminderItemDto.setEquipName(registerInfo.getProductName());
        reminderItemDto.setDetailData(newEquipParseService.getEquipDetailByRecord(bizId));
        page.setRecords(Collections.singletonList(reminderItemDto));
        page.setTotal(1L);
        return page;
    }

    @Override
    public IPage<ReminderItemDto> jsonParse(String bizId, Map<String, Object> formData, Page<ReminderItemDto> page) {
        IdxBizJgRegisterInfo registerInfo = newEquipParseService.getRegisterInfoFromJson(formData);
        ReminderItemDto reminderItemDto = new ReminderItemDto();
        reminderItemDto.setEquipId(bizId);
        reminderItemDto.setEquipNo(registerInfo.getEquCode());
        reminderItemDto.setEquipName(registerInfo.getProductName());
        reminderItemDto.setDetailData(newEquipParseService.getDetailInfoFromJson(formData));
        page.setRecords(Collections.singletonList(reminderItemDto));
        page.setTotal(1L);
        return page;
    }

    @Override
    public MatchItemDto getMatchItem(String bizId, Map<String, Object> formData) {
        MatchItemDto matchItemDto = MatchItemDto.builder().build();
        newEquipParseService.setEquCateInfoForInsert(formData, matchItemDto);
        matchItemDto.setRegType(newEquipParseService.getRegTypeForInsert(formData));
        return matchItemDto;
    }

    @Override
    public MatchItemDto getMatchItem(String bizId) {
        MatchItemDto matchItemDto = MatchItemDto.builder().build();
        newEquipParseService.setEquCateInfoForEdit(bizId, matchItemDto);
        matchItemDto.setRegType(newEquipParseService.getRegTypeForEdit(bizId));
        return matchItemDto;
    }

    @Override
    public String supportBizType() {
        return BusinessTypeEnum.JG_NEW_EQUIP.name();
    }
}
