package com.xunhong.erp.turbo.admin.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.dto.PageResponse;
import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import com.xunhong.erp.turbo.api.biz.api.GiftBoxServiceI;
import com.xunhong.erp.turbo.api.biz.dto.cmd.GiftBoxCreateCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.GiftBoxDestroyCmd;
import com.xunhong.erp.turbo.api.biz.dto.cmd.GiftBoxUpdateCmd;
import com.xunhong.erp.turbo.api.biz.dto.qry.GiftBoxListQry;
import com.xunhong.erp.turbo.api.biz.dto.qry.GiftBoxPageQry;
import com.xunhong.erp.turbo.api.biz.dto.qry.GiftBoxShowQry;
import com.xunhong.erp.turbo.api.biz.dto.vo.GiftBoxVO;
import com.xunhong.erp.turbo.base.dto.PageDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author shenyifei
 */
@Tag(name = "GiftBox", description = "礼盒管理")
@RestController("operationGiftBoxController")
@RequestMapping(value = "/operation")
@RequiredArgsConstructor
public class GiftBoxController {

	@DubboReference(version = "1.0.0")
	private final GiftBoxServiceI giftBoxService;

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_GIFT_BOX_VIEW})
	@GetMapping("listGiftBox")
	@Operation(summary = "礼盒列表", method = "GET")
	public MultiResponse<GiftBoxVO> listGiftBox(@ModelAttribute @Validated GiftBoxListQry giftBoxListQry) {
		return MultiResponse.of(giftBoxService.list(giftBoxListQry));
	}

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_GIFT_BOX_CREATE})
	@PostMapping("createGiftBox")
	@Operation(summary = "创建礼盒", method = "POST")
	public SingleResponse<GiftBoxVO> createGiftBox(@RequestBody @Validated GiftBoxCreateCmd giftBoxCreateCmd) {
		return SingleResponse.of(giftBoxService.create(giftBoxCreateCmd));
	}

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_GIFT_BOX_VIEW})
	@GetMapping("showGiftBox")
	@Operation(summary = "礼盒详情", method = "GET")
	public SingleResponse<GiftBoxVO> showGiftBox(@ModelAttribute @Validated GiftBoxShowQry giftBoxShowQry) {
		return SingleResponse.of(giftBoxService.show(giftBoxShowQry));
	}

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_GIFT_BOX_VIEW})
	@GetMapping("pageGiftBox")
	@Operation(summary = "礼盒列表", method = "GET")
	public PageResponse<GiftBoxVO> pageGiftBox(@ModelAttribute @Validated GiftBoxPageQry giftBoxPageQry) {
		PageDTO<GiftBoxVO> page = giftBoxService.page(giftBoxPageQry);
		return PageResponse.of(page.getRecords(), (int) page.getTotal(), (int) page.getSize(), (int) page.getCurrent());
	}

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_GIFT_BOX_UPDATE})
	@RequestMapping(value = "updateGiftBox", method = {RequestMethod.PATCH, RequestMethod.PUT})
	@Operation(summary = "礼盒更新", method = "PATCH")
	public SingleResponse<GiftBoxVO> updateGiftBox(@RequestBody @Validated GiftBoxUpdateCmd giftBoxUpdateCmd) {
		return SingleResponse.of(giftBoxService.update(giftBoxUpdateCmd));
	}

	@SaCheckLogin
//    @SaCheckPermission(value = {PermissionConstant.MDB_BUSINESS_GIFT_BOX_DELETE})
	@DeleteMapping("destroyGiftBox")
	@Operation(summary = "礼盒删除", method = "DELETE")
	public Response destroyGiftBox(@RequestBody @Validated GiftBoxDestroyCmd giftBoxDestroyCmd) {
		giftBoxService.destroy(giftBoxDestroyCmd);
		return Response.buildSuccess();
	}
}
