package com.hdkj.lt.bf.controller;

import com.hdkj.lt.base.model.response.PageVO;
import com.hdkj.lt.bf.entity.dto.*;
import com.hdkj.lt.bf.entity.vo.NoticeFileListVO;
import com.hdkj.lt.bf.entity.vo.NoticeListVO;
import com.hdkj.lt.bf.entity.vo.NoticeVO;
import com.hdkj.lt.bf.service.FhzgNoticeService;
import com.hdkj.hussar.ApiResponse;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author rj
 * @date 2025/12/26 10:21
 * @description
 */
@RestController
@AllArgsConstructor
@RequestMapping("/notice")
public class FhzgNoticeController {

    private final FhzgNoticeService fhzgNoticeService;


    /**
     * 文件下载tab列表
     */
    @ApiOperation(value = "文件tab列表")
    @GetMapping("/file-tab-list")
    public ApiResponse<List<AttachmentDTO>> getFileTabList() {
        return ApiResponse.success(fhzgNoticeService.getFileTabList());
    }

    /**
     * 文件下载列表
     */
    @ApiOperation(value = "文件列表")
    @PostMapping("/file-list")
    public ApiResponse<PageVO<NoticeFileListVO>> getFileList(@Valid @RequestBody NoticeFileListDTO noticeFileListDTO) {
        return ApiResponse.success(fhzgNoticeService.getFileList(noticeFileListDTO));
    }

    /**
     * 后台管理通知列表
     */
    @ApiOperation(value = "后台文档列表")
    @PostMapping("/list")
    public ApiResponse<PageVO<NoticeListVO>> getList(@Valid @RequestBody NoticeListDTO noticeListDTO) {
        return ApiResponse.success(fhzgNoticeService.getList(noticeListDTO));
    }

    /**
     * 前台管理通知列表
     */
    @ApiOperation(value = "前台管理通知列表")
    @PostMapping("/notice-list")
    public ApiResponse<PageVO<NoticeListVO>> getNoticeList(@Valid @RequestBody NoticeListDTO noticeListDTO) {
        return ApiResponse.success(fhzgNoticeService.getNoticeList(noticeListDTO));
    }

    /**
     * 全部已读
     */
    @ApiOperation(value = "全部已读")
    @PostMapping("/read-all")
    public ApiResponse<String> readAll() {
        fhzgNoticeService.readAll();
        return ApiResponse.success("全部已读");
    }

    /**
     * 后台管理通知状态更新
     */
    @ApiOperation(value = "后台管理通知状态更新")
    @PostMapping("/update")
    public ApiResponse<String> update(@Valid @RequestBody NoticeUpdateDTO noticeUpdateDTO) {
        fhzgNoticeService.update(noticeUpdateDTO);
        return ApiResponse.success("更新成功");
    }

    /**
     * 文档更新
     */
    @ApiOperation(value = "文档更新")
    @PostMapping("/file-update")
    public ApiResponse<String> fileUpdate(@Valid @RequestBody NoticeUpdateDTO noticeUpdateDTO) {
        fhzgNoticeService.fileUpdate(noticeUpdateDTO);
        return ApiResponse.success("更新成功");
    }

    /**
     * 文档更新
     */
    @ApiOperation(value = "文档下架")
    @PostMapping("/file-down")
    public ApiResponse<String> fileDown(@Valid @RequestBody NoticeUpdateDTO noticeUpdateDTO) {
        fhzgNoticeService.fileDown(noticeUpdateDTO);
        return ApiResponse.success("下架成功");
    }

    /**
     * 文档删除
     */
    @ApiOperation(value = "文档删除")
    @PostMapping("/file-delete")
    public ApiResponse<String> fileDelete(@Valid @RequestBody NoticeUpdateDTO noticeUpdateDTO) {
        fhzgNoticeService.fileDelete(noticeUpdateDTO);
        return ApiResponse.success("删除成功");
    }

    /**
     * 新增通知
     */
    @ApiOperation(value = "新增通知")
    @PostMapping("/add")
    public ApiResponse<String> update(@Valid @RequestBody NoticeAddDTO noticeAddDTO) {
        fhzgNoticeService.add(noticeAddDTO);
        return ApiResponse.success("发布成功");
    }

    /**
     * 删除通知
     */
    @ApiOperation(value = "删除通知")
    @PostMapping("/delete")
    public ApiResponse<String> delete(@Valid @RequestBody NoticeUpdateDTO noticeUpdateDTO) {
        fhzgNoticeService.delete(noticeUpdateDTO);
        return ApiResponse.success("删除成功");
    }


    /**
     * 通知详情
     */
    @ApiOperation(value = "通知详情")
    @GetMapping("/{id}")
    public ApiResponse<NoticeVO> getById(@PathVariable Long id) {
        return ApiResponse.success(fhzgNoticeService.getDetailById(id));
    }

}
