package com.snack.server.module.notice.controller;

import com.snack.server.common.Result;
import com.snack.server.module.notice.service.NoticeService;
import com.snack.server.module.notice.vo.NoticeVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 公告（用户端 / 公开接口）
 */
@Tag(name = "公告（公开）")
@RestController
@RequestMapping("/api/notice")
@RequiredArgsConstructor
public class NoticePublicController {

    private final NoticeService noticeService;

    @Operation(summary = "获取当前生效的公告（首页/公告中心）")
    @GetMapping("/list")
    public Result<List<NoticeVO>> list() {
        return Result.ok(noticeService.listActiveNotices());
    }

    @Operation(summary = "公告详情 + 增加浏览量")
    @GetMapping("/{id}")
    public Result<NoticeVO> detail(@PathVariable Long id) {
        NoticeVO vo = noticeService.getNoticeById(id);
        noticeService.incrViewCount(id);
        return Result.ok(vo);
    }
}
