package com.mirs.biz.controller;

import com.mirs.biz.domain.BrdfData;
import com.mirs.biz.domain.EmiMeasurement;
import com.mirs.biz.domain.IntegratedData;
import com.mirs.biz.domain.Sample;
import com.mirs.biz.dto.IndexResultDTO;
import com.mirs.biz.dto.IndexSearchDTO;
import com.mirs.biz.service.IBrdfDataService;
import com.mirs.biz.service.IEmiMeasurementService;
import com.mirs.biz.service.IIntegratedDataService;
import com.mirs.biz.service.ISampleService;
import com.mirs.common.core.controller.BaseController;
import com.mirs.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/index/search")
public class IndexController extends BaseController {
    @Autowired
    private IBrdfDataService brdfDataService;
    @Autowired
    private IEmiMeasurementService emiMeasurementService;

    @Autowired
    private IIntegratedDataService integratedDataService;

    @Autowired
    private ISampleService sampleService;
    /**
     * 查询主页的数据
     */

    @GetMapping("/getIndexInfo")
    public AjaxResult getIndexInfo(IndexSearchDTO dto) {
        IndexResultDTO indexResultDTO = new IndexResultDTO();
        Sample sample = sampleService.getOne(dto.getSample());

        if (sample == null) {
            indexResultDTO.setBrdfDataList(new ArrayList<>());
            indexResultDTO.setEmiMeasurementList(new ArrayList<>());
            indexResultDTO.setIntegratedDataList(new ArrayList<>());
            return success(indexResultDTO);
        }
        List<BrdfData> brdfData = brdfDataService.selectBrdfDataList(dto.getBrdfData());
        List<EmiMeasurement> emiMeasurementList = emiMeasurementService.selectEmiMeasurementList(dto.getEmiMeasurement());
        List<IntegratedData> integratedDataList = integratedDataService.selectIntegratedDataList(dto.getIntegratedData());

        indexResultDTO.setSample(sample);
        indexResultDTO.setBrdfDataList(brdfData);
        indexResultDTO.setEmiMeasurementList(emiMeasurementList);
        indexResultDTO.setIntegratedDataList(integratedDataList);

        return success(indexResultDTO);
    }

    @GetMapping("/getSampleType")
    public AjaxResult getSampleType(IndexSearchDTO dto) {
        return success(sampleService.getSampleType(dto.getDataType()));
    }

    @GetMapping("/getSampleModel")
    public AjaxResult getSampleModel(IndexSearchDTO dto) {
        return success(sampleService.getSampleModel(dto));
    }

    @GetMapping("/getTemperatureK")
    public AjaxResult getTemperatureK(IndexSearchDTO dto) {
        if("1".equals(dto.getDataType())){
            return success(emiMeasurementService.getTemperatureK());
        } else {
            return success(brdfDataService.getTemperatureK());
        }
    }

    @GetMapping("/getAllAngle")
    public AjaxResult getAllAngle() {
        return success(brdfDataService.getAllAngle());
    }
    @GetMapping("/getOthersOptions")
    public AjaxResult getOthersOptions(IndexSearchDTO dto) {
        Map<String, Object> result = new HashMap<>(4);
        result.put("sampleTypeOptions", sampleService.getSampleType(dto.getDataType()));
        result.put("sampleModelOptions", sampleService.getSampleModel(dto));
        if("1".equals(dto.getDataType())){
            result.put("temperatureKOptions", emiMeasurementService.getTemperatureK());

            Map<String, Object> resultMap = new HashMap<>(4);
            resultMap.put("thetaIncidentOptions", new ArrayList<>());
            resultMap.put("phiIncidentOptions", new ArrayList<>());
            resultMap.put("thetaReflectedOptions", new ArrayList<>());
            resultMap.put("phiReflectedOptions", new ArrayList<>());
            result.put("allAngleOptions", resultMap);
        } else {
            result.put("temperatureKOptions", brdfDataService.getTemperatureK());

            result.put("allAngleOptions", brdfDataService.getAllAngle());
        }
        return success(result);
    }
}
