package cn.stylefeng.team.portal.modular.management.controller;

import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import cn.stylefeng.team.portal.modular.management.entity.PortalNews;
import cn.stylefeng.team.portal.modular.management.pojo.request.PortalNewsRequest;
import cn.stylefeng.team.portal.modular.management.service.PortalNewsService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@ApiResource(name = "新闻")
public class PortalNewsController {

    @Resource
    private PortalNewsService portalNewsService;

    @PostResource(name = "添加新闻", path = "/portalNews/add")
    public ResponseData<PortalNews> add(@RequestBody @Validated(PortalNewsRequest.add.class) PortalNewsRequest portalNewsRequest) {
        portalNewsService.add(portalNewsRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "删除新闻", path = "/portalNews/delete")
    public ResponseData<?> delete(@RequestBody @Validated(PortalNewsRequest.delete.class) PortalNewsRequest portalNewsRequest) {
        portalNewsService.del(portalNewsRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "批量删除新闻", path = "/portalNews/batchDelete")
    public ResponseData<?> batchDelete(@RequestBody @Validated(BaseRequest.batchDelete.class) PortalNewsRequest portalNewsRequest) {
        portalNewsService.batchDelete(portalNewsRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "编辑新闻", path = "/portalNews/edit")
    public ResponseData<?> edit(@RequestBody @Validated(PortalNewsRequest.edit.class) PortalNewsRequest portalNewsRequest) {
        portalNewsService.edit(portalNewsRequest);
        return new SuccessResponseData<>();
    }

    @GetResource(name = "查看新闻详情", path = "/portalNews/detail")
    public ResponseData<PortalNews> detail(@Validated(PortalNewsRequest.detail.class) PortalNewsRequest portalNewsRequest) {
        return new SuccessResponseData<>(portalNewsService.detail(portalNewsRequest));
    }

    @GetResource(name = "获取新闻列表（带分页）", path = "/portalNews/page")
    public ResponseData<PageResult<PortalNews>> page(@Validated(PortalNewsRequest.page.class) PortalNewsRequest portalNewsRequest) {
        return new SuccessResponseData<>(portalNewsService.findPage(portalNewsRequest));
    }

    @GetResource(name = "获取新闻下拉选择列表", path = "/portalNews/getSelect")
    public ResponseData<List<PortalNews>> getSelect(@Validated(PortalNewsRequest.page.class) PortalNewsRequest portalNewsRequest) {
        return new SuccessResponseData<>(portalNewsService.getSelect(portalNewsRequest));
    }

}
