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.PortalAppLink;
import cn.stylefeng.team.portal.modular.management.pojo.request.PortalAppLinkRequest;
import cn.stylefeng.team.portal.modular.management.service.PortalAppLinkService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@ApiResource(name = "应用链接")
public class PortalAppLinkController {

    @Resource
    private PortalAppLinkService portalAppLinkService;

    @PostResource(name = "添加应用链接", path = "/portalAppLink/add")
    public ResponseData<PortalAppLink> add(@RequestBody @Validated(PortalAppLinkRequest.add.class) PortalAppLinkRequest portalAppLinkRequest) {
        portalAppLinkService.add(portalAppLinkRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "删除应用链接", path = "/portalAppLink/delete")
    public ResponseData<?> delete(@RequestBody @Validated(PortalAppLinkRequest.delete.class) PortalAppLinkRequest portalAppLinkRequest) {
        portalAppLinkService.del(portalAppLinkRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "批量删除应用链接", path = "/portalAppLink/batchDelete")
    public ResponseData<?> batchDelete(@RequestBody @Validated(BaseRequest.batchDelete.class) PortalAppLinkRequest portalAppLinkRequest) {
        portalAppLinkService.batchDelete(portalAppLinkRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "编辑应用链接", path = "/portalAppLink/edit")
    public ResponseData<?> edit(@RequestBody @Validated(PortalAppLinkRequest.edit.class) PortalAppLinkRequest portalAppLinkRequest) {
        portalAppLinkService.edit(portalAppLinkRequest);
        return new SuccessResponseData<>();
    }

    @GetResource(name = "查看应用链接详情", path = "/portalAppLink/detail")
    public ResponseData<PortalAppLink> detail(@Validated(PortalAppLinkRequest.detail.class) PortalAppLinkRequest portalAppLinkRequest) {
        return new SuccessResponseData<>(portalAppLinkService.detail(portalAppLinkRequest));
    }

    @GetResource(name = "获取应用链接列表（带分页）", path = "/portalAppLink/page")
    public ResponseData<PageResult<PortalAppLink>> page(PortalAppLinkRequest portalAppLinkRequest) {
        return new SuccessResponseData<>(portalAppLinkService.findPage(portalAppLinkRequest));
    }

}
