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.common.core.constant.OperationConstant;
import com.sptg.estate.api.dto.NoticePushDto;
import com.sptg.estate.api.dto.UserDto;
import com.sptg.estate.api.entity.NoticePush;
import com.sptg.estate.api.entity.NoticePushDetails;
import com.sptg.estate.api.entity.NoticePushImg;
import com.sptg.estate.api.entity.User;
import com.sptg.estate.api.feigns.NoticePushFeign;
import com.sptg.estate.biz.service.NoticePushDetailsServiceInterface;
import com.sptg.estate.biz.service.NoticePushImgServiceInterface;
import com.sptg.estate.biz.service.NoticePushServiceInterface;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * title: NoticePushDetailsController
 * package: com.sptg.estate.biz.controller
 * description: 公告发布详细-控制器
 *
 *                
 *                
 */
@RestController
public class NoticePushController implements NoticePushFeign {
    private final NoticePushServiceInterface noticePushServiceInterface;
    private final NoticePushImgServiceInterface noticePushImgServiceInterface;
    private final NoticePushDetailsServiceInterface noticePushDetailsServiceInterface;

    @Autowired
    public NoticePushController(NoticePushServiceInterface noticePushServiceInterface,
                                NoticePushImgServiceInterface noticePushImgServiceInterface,
                                NoticePushDetailsServiceInterface noticePushDetailsServiceInterface) {
        this.noticePushServiceInterface = noticePushServiceInterface;
        this.noticePushImgServiceInterface = noticePushImgServiceInterface;
        this.noticePushDetailsServiceInterface = noticePushDetailsServiceInterface;
    }
    @Override
    @PostMapping(value = "/noticePush/showNoticePushList")
    public ResultBean<Page<NoticePush>> showNoticePushList(@RequestBody NoticePushDto noticePushDto) {
        Page<NoticePush> page= noticePushServiceInterface.showNoticePushList(noticePushDto);
        return new ResultBean<>(ResultEnum.SUCCESS,page);
    }
    @Override
    @PostMapping(value = "/noticePush/addNoticePush")
    public ResultBean<Long> addNoticePush(@RequestBody NoticePush noticePush) {
        Long id= noticePushServiceInterface.addNoticePush(noticePush);
        return new ResultBean<>(ResultEnum.SUCCESS,id);
    }
    @Override
    @PostMapping(value = "/noticePush/findNoticePushById")
    public ResultBean<NoticePush> findNoticePushById(@RequestParam(value = "id") long id) {
        NoticePush noticePush=noticePushServiceInterface.findNoticePushById(id);
        return new ResultBean<>(ResultEnum.SUCCESS,noticePush);
    }
    @Override
    @GetMapping(value = "/noticePush/cancelNoticePush/{id}")
    public ResultBean<Boolean> cancelNoticePush(@PathVariable("id") long id) {
        boolean result= noticePushServiceInterface.updatePushStatus(id, OperationConstant.THREE);
        return new ResultBean<>(ResultEnum.SUCCESS,result);
    }

    @Override
    @GetMapping(value = "/noticePush/selectNoticePushImgList/{noticePushId}")
    public List<NoticePushImg> selectNoticePushImgList(@PathVariable("noticePushId") long noticePushId){
        return noticePushImgServiceInterface.selectNoticePushImgList(noticePushId);
    }

    @Override
    @GetMapping(value = "/noticePush/getListByNoticePushId/{noticePushId}")
    public List<NoticePushDetails> getListByNoticePushId(@PathVariable("noticePushId") long noticePushId){
       return noticePushDetailsServiceInterface.getListByNoticePushId(noticePushId);
    }

    @Override
    @PostMapping(value = "/noticePush/updateNoticePushById")
    public Boolean updateNoticePushById(@RequestBody NoticePush noticePush){
        return noticePushServiceInterface.updateById(noticePush);
    }

    @Override
    @PostMapping(value = "/noticePush/getListByUser")
    public List<NoticePush> getListByUser(@RequestBody UserDto userDto) {
        return noticePushServiceInterface.getListByUser(userDto);
    }
}
