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.NoticeDto;
import com.sptg.estate.api.entity.Notice;
import com.sptg.estate.api.feigns.NoticeFeign;
import com.sptg.estate.biz.service.NoticeImgServiceInterface;
import com.sptg.estate.biz.service.NoticeServiceInterface;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * title: NoticeController
 * package: com.sptg.estate.biz.controller
 * description: 公告-控制器
 *
 *                
 *                
 */
@RestController
public class NoticeController implements NoticeFeign {
    private final NoticeServiceInterface noticeServiceInterface;
    private final NoticeImgServiceInterface noticeImageServiceInterface;
    @Autowired
    public NoticeController(NoticeServiceInterface noticeServiceInterface, NoticeImgServiceInterface noticeImageServiceInterface) {
        this.noticeServiceInterface = noticeServiceInterface;
        this.noticeImageServiceInterface = noticeImageServiceInterface;
    }
    @Override
    @PostMapping(value = "/notice/showNoticeList")
    public ResultBean<Page<Notice>> showNoticeList(@RequestBody NoticeDto noticeDto) {
        Page<Notice> page=noticeServiceInterface.showNoticeList(noticeDto);
        return new ResultBean<>(ResultEnum.SUCCESS,page);
    }
    @Override
    @PostMapping(value = "/notice/getList")
    public ResultBean<List<Notice>> getList(@RequestBody NoticeDto noticeDto) {
        List<Notice> list=noticeServiceInterface.getList(noticeDto);
        return new ResultBean<List<Notice>>(ResultEnum.SUCCESS,list);
    }
    @Override
    @PostMapping(value = "/notice/addOrEditNotice")
    public ResultBean<Boolean> addOrEditNotice(@RequestBody Notice notice){
        boolean result = noticeServiceInterface.addOrEditNotice(notice);
        return new ResultBean<>(ResultEnum.SUCCESS,result);
    }
    @Override
    @PostMapping(value = "/notice/findNoticeById")
    public ResultBean<Notice> findNoticeById(@RequestParam(value = "id") long id){
        Notice notice =  noticeServiceInterface.findNoticeById(id);
        return new ResultBean<>(ResultEnum.SUCCESS,notice);
    }
    @Override
    @PostMapping(value = "/notice/deleteNoticeById")
    public ResultBean<Boolean> deleteNoticeById(@RequestParam(value = "id") long id){
        boolean result  =  noticeServiceInterface.deleteNoticeById(id);
        return new ResultBean<>(ResultEnum.SUCCESS,result);
    }
    @Override
    @PostMapping(value = "/notice/deleteNoticeList")
    public ResultBean<Boolean> deleteNoticeList(@RequestBody NoticeDto noticeDto){
        return  this.noticeServiceInterface.deleteNoticeList(noticeDto);
    }

    @Override
    @PostMapping(value = "/notice/updateNoticeList")
    public boolean updateNoticeList(@RequestBody List<Notice> noticeList) {
        return this.noticeServiceInterface.updateBatchById(noticeList);
    }
}
