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.PortalDesignPermission;
import cn.stylefeng.team.portal.modular.management.pojo.request.PermissionUpdateRequest;
import cn.stylefeng.team.portal.modular.management.pojo.request.PortalDesignPermissionRequest;
import cn.stylefeng.team.portal.modular.management.service.PortalDesignPermissionService;
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 PortalDesignPermissionController {

    @Resource
    private PortalDesignPermissionService portalDesignPermissionService;

    @PostResource(name = "更新门户设计的生效范围", path = "/portalDesignPermission/updatePermissionList")
    public ResponseData<PortalDesignPermission> updatePermissionList(@RequestBody @Validated PermissionUpdateRequest permissionUpdateRequest) {
        portalDesignPermissionService.updatePermissionList(permissionUpdateRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "删除门户设计生效范围", path = "/portalDesignPermission/delete")
    public ResponseData<?> delete(@RequestBody @Validated(PortalDesignPermissionRequest.delete.class) PortalDesignPermissionRequest portalDesignPermissionRequest) {
        portalDesignPermissionService.del(portalDesignPermissionRequest);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "批量删除门户设计生效范围", path = "/portalDesignPermission/batchDelete")
    public ResponseData<?> batchDelete(@RequestBody @Validated(BaseRequest.batchDelete.class) PortalDesignPermissionRequest portalDesignPermissionRequest) {
        portalDesignPermissionService.batchDelete(portalDesignPermissionRequest);
        return new SuccessResponseData<>();
    }

    @GetResource(name = "获取门户设计生效范围列表（带分页）", path = "/portalDesignPermission/page")
    public ResponseData<PageResult<PortalDesignPermission>> page(@Validated(BaseRequest.page.class) PortalDesignPermissionRequest portalDesignPermissionRequest) {
        return new SuccessResponseData<>(portalDesignPermissionService.findPage(portalDesignPermissionRequest));
    }

}
