package com.zhongshu.card.server.core.controller.school;

import com.github.microservice.auth.security.annotations.ResourceAuth;
import com.github.microservice.auth.security.type.AuthType;
import com.zhongshu.card.client.model.base.IDParam;
import com.zhongshu.card.client.model.school.*;
import com.github.microservice.net.ResultContent;
import com.zhongshu.card.client.service.school.NoticeInfoService;
import com.zhongshu.card.server.core.service.user.RoleServiceImpl;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author TRX
 * @date 2024/6/5
 */
@RestController
@RequestMapping("/school/notice")
@Tag(name = "学校-校园公告")
public class NoticeController {

    @Autowired
    RoleServiceImpl roleService;

    @Autowired
    NoticeInfoService noticeInfoService;

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "添加-编辑公告", description = "添加-编辑公告")
    @RequestMapping(value = "addNoticeInfo", method = {RequestMethod.POST})
    public ResultContent addNoticeInfo(@RequestBody NoticeInfoAddParam param) {
        return this.noticeInfoService.addNoticeInfo(param);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "删除公告", description = "删除公告")
    @RequestMapping(value = "deleteNoticeInfo", method = {RequestMethod.POST})
    public ResultContent deleteNoticeInfo(@RequestBody IDParam param) {
        return this.noticeInfoService.deleteNoticeInfo(param.getId());
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "置顶公告", description = "置顶公告")
    @RequestMapping(value = "topping", method = {RequestMethod.POST})
    public ResultContent topping(@RequestBody IDParam param) {
        return this.noticeInfoService.topping(param.getId());
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "公告详情", description = "公告详情")
    @RequestMapping(value = "getDetail", method = {RequestMethod.POST})
    public ResultContent<NoticeInfoModel> getDetail(@RequestBody IDParam param) {
        return this.noticeInfoService.getDetail(param.getId());
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "公告增加阅读量", description = "公告增加阅读量")
    @RequestMapping(value = "addView", method = {RequestMethod.POST})
    public ResultContent addView(@RequestBody IDParam param) {
        return this.noticeInfoService.addView(param.getId());
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "公告列表-分页查询", description = "公告列表-分页查询")
    @RequestMapping(value = {"page"}, method = {RequestMethod.POST})
    public ResultContent<Page<NoticeInfoModel>> page(
            @Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
            @Parameter(required = false) NoticeInfoSearchParam param) {
        return noticeInfoService.page(param, pageable);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "公告阅读量列表-分页查询", description = "公告阅读量-分页查询")
    @RequestMapping(value = {"pageView"}, method = {RequestMethod.POST})
    public ResultContent<Page<NoticeInfoViewModel>> pageView(
            @Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
            @Parameter(required = false) NoticeInfoViewSearch param) {
        return noticeInfoService.pageView(param, pageable);
    }
}
