package cn.newfeifan.mall.module.promotion.controller.app.diy;

import cn.newfeifan.mall.framework.common.pojo.CommonResult;
import cn.newfeifan.mall.framework.common.pojo.PageResult;
import cn.newfeifan.mall.framework.common.util.object.BeanUtils;
import cn.newfeifan.mall.module.promotion.controller.admin.diy.vo.page.DiyPagePageReqVO;
import cn.newfeifan.mall.module.promotion.controller.admin.diy.vo.page.DiyPageRespVO;
import cn.newfeifan.mall.module.promotion.controller.app.diy.vo.AppDiyPagePropertyRespVO;
import cn.newfeifan.mall.module.promotion.convert.diy.DiyPageConvert;
import cn.newfeifan.mall.module.promotion.dal.dataobject.diy.DiyPageDO;
import cn.newfeifan.mall.module.promotion.service.diy.DiyPageService;
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.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

import static cn.newfeifan.mall.framework.common.pojo.CommonResult.success;

@Tag(name = "用户 APP - 装修页面")
@RestController
@RequestMapping("/promotion/diy-page")
@Validated
public class AppDiyPageController {

    @Resource
    private DiyPageService diyPageService;

    @GetMapping("/get")
    @Operation(summary = "获得装修页面")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<AppDiyPagePropertyRespVO> getDiyPage(@RequestParam("shopId") Long shopId,@RequestParam("merchantId") Long merchantId) {
        DiyPageDO diyPage = diyPageService.getDiyPage(shopId, merchantId);
        return success(BeanUtils.toBean(diyPage, AppDiyPagePropertyRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得装修页面分页")
    @PreAuthorize("@ss.hasPermission('promotion:diy-page:query')")
    public CommonResult<PageResult<DiyPageRespVO>> getDiyPagePage(@Valid DiyPagePageReqVO pageVO) {
        PageResult<DiyPageDO> pageResult = diyPageService.getDiyPagePage(pageVO);
        return success(DiyPageConvert.INSTANCE.convertPage(pageResult));
    }

}
