package com.sptg.estate.biz.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.core.beans.ResultEnum;
import com.sptg.estate.api.dto.PositionDto;
import com.sptg.estate.api.entity.EnvironmentalReview;
import com.sptg.estate.api.entity.InstallationReview;
import com.sptg.estate.api.entity.Position;
import com.sptg.estate.api.entity.PositionRecord;
import com.sptg.estate.api.feigns.PositionFeign;
import com.sptg.estate.biz.service.EnvironmentalReviewServiceInterface;
import com.sptg.estate.biz.service.InstallationReviewServiceInterface;
import com.sptg.estate.biz.service.PositionRecordServiceInterface;
import com.sptg.estate.biz.service.PositionServiceInterface;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * title: PositionController
 * package: com.sptg.estate.biz.controller
 * description:
 *
 *                
 *                
 */
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/implement/position")
public class PositionController implements PositionFeign {

    private final PositionServiceInterface positionServiceInterface;
    private final PositionRecordServiceInterface positionRecordServiceInterface;
    private final EnvironmentalReviewServiceInterface environmentalReviewServiceInterface;
    private final InstallationReviewServiceInterface installationReviewServiceInterface;

    @Override
    @PostMapping("/showList")
    public ResultBean<Page<Position>> showList(@RequestBody PositionDto dto){
        Page<Position> positionPage = this.positionServiceInterface.showList(dto);
        return new ResultBean<>(ResultEnum.SUCCESS,positionPage);
    }

    @Override
    @PostMapping("/findById")
    public ResultBean<Position> findById(@RequestBody Long id) {
        Position position =null;
        if(id!=null&&id>0){
            position = this.positionServiceInterface.selectById(id);
        }
        return new ResultBean<>(ResultEnum.SUCCESS,position);
    }

    @Override
    @PostMapping("/findByProjectId")
    public ResultBean<Position> findByProjectId(@RequestBody Long projectId) {
        return this.positionServiceInterface.findByProjectId(projectId);
    }

    @Override
    @PostMapping("/getPositionRecordListById")
    public List<PositionRecord> getPositionRecordListById(@RequestBody Long id) {
        if(id==null||id<=0){
            return null;
        }
        List<PositionRecord> positionRecordList = this.positionRecordServiceInterface.getListByPositionId(id);
        return positionRecordList;
    }

    @Override
    @PostMapping("/getEnvironmentalReviewListById")
    public List<EnvironmentalReview> getEnvironmentalReviewListById(@RequestBody Long id) {
        if(id==null||id<=0){
            return null;
        }
        List<EnvironmentalReview> environmentalReviews = this.environmentalReviewServiceInterface.getListByPositionId(id);
        return environmentalReviews;
    }

    @Override
    @PostMapping("/getInstallationReviewListById")
    public List<InstallationReview> getInstallationReviewListById(@RequestBody Long id) {
        if(id==null||id<=0){
           return null;
        }
        List<InstallationReview> installationReviews = this.installationReviewServiceInterface.getListByPositionId(id);
        return installationReviews;
    }

    @Override
    @PostMapping("/countByOrgPosition")
    public ResultBean<Integer> countByOrgPosition(@RequestBody String orgPosition) {
        return this.positionServiceInterface.countByOrgPosition(orgPosition);
    }

    @Override
    @PostMapping("/checkState")
    public ResultBean<Boolean> checkState(@RequestBody PositionDto dto) {
        boolean result = this.positionServiceInterface.checkState(dto);
        return new ResultBean<>(ResultEnum.SUCCESS,result);
    }

    @Override
    @PostMapping("/findListByPosition")
    public ResultBean<Position> findListByPosition(@RequestBody PositionDto dto) {
        return this.positionServiceInterface.findListByPosition(dto);
    }

    @Override
    @PostMapping("/countByProjectId")
    public ResultBean<Boolean> countByProjectId(@RequestBody Long projectId) {
        return this.positionServiceInterface.countByProjectId(projectId);
    }

    @Override
    @PostMapping("/insert")
    public ResultBean<Boolean> insert(@RequestBody PositionDto dto) {
        return this.positionServiceInterface.insertEntity(dto);
    }

    @Override
    @PostMapping("/editEntity")
    public ResultBean<Boolean> editEntity(@RequestBody PositionDto dto) {
        return this.positionServiceInterface.editEntity(dto);
    }

}
