/*
 * Copyright (c) 2018-2999 广州亚米信息科技有限公司 All rights reserved.
 *
 * https://www.gz-yami.com/
 *
 * 未经允许，不可做商业用途！
 *
 * 版权所有，侵权必究！
 */

package com.yami.shop.distribution.platform.controller;

import com.yami.shop.common.config.Constant;
import com.yami.shop.common.util.Json;
import com.yami.shop.distribution.comment.model.DistributionBindSet;
import com.yami.shop.distribution.comment.service.DistributionBindSetService;
import com.yami.shop.security.platform.util.SecurityUtils;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 绑定设置
 * @author lgh on 2019/04/01.
 */
@RestController
@RequestMapping("/platform/distributionBindSet")
@AllArgsConstructor
public class DistributionBindSetController {

    private DistributionBindSetService distributionBindSetService;

	/**
	 * 获取信息(根据店铺)
	 */
	@GetMapping("/info")
	@PreAuthorize("@pms.hasPermission('platform:distributionBindSet:info')")
	public ResponseEntity<DistributionBindSet> info(){
		return ResponseEntity.ok(distributionBindSetService.getByShopId());
	}

	/**
	 * 修改
	 */
	@PutMapping
	@PreAuthorize("@pms.hasPermission('platform:distributionBindSet:update')")
	public ResponseEntity<Void> update(@RequestBody @Valid DistributionBindSet distributionBindSet){
		Long shopId = Constant.PLATFORM_SHOP_ID;

		distributionBindSet.setBindSceneJson(Json.toJsonString(distributionBindSet.getBindScene()));
		distributionBindSet.setRobJson(Json.toJsonString(distributionBindSet.getRob()));
		distributionBindSet.setShopId(shopId);
		distributionBindSet.setModifier(SecurityUtils.getSysUser().getUserId());
		distributionBindSetService.updateById(distributionBindSet);
		distributionBindSetService.removeCacheByShopId(shopId);
		return ResponseEntity.ok().build();
	}

//	/**
//	 * 分页获取
//	 */
//   @GetMapping("/page")
//  @PreAuthorize("@pms.hasPermission('platform:distributionBindSet:page')")
//	public ResponseEntity<IPage<DistributionBindSet>> page(DistributionBindSet distributionBindSet,PageParam<DistributionBindSet> page){
//		IPage<DistributionBindSet> list = distributionBindSetService.page(page,new LambdaQueryWrapper<DistributionBindSet>());
//		return ResponseEntity.ok(list);
//	}

//  /**
//	 * 获取信息
//	 */
//	@GetMapping("/info/{id}")
//	@PreAuthorize("@pms.hasPermission('platform:distributionBindSet:info')")
//	public ResponseEntity<DistributionBindSet> info(@PathVariable("id") Long id){
//		DistributionBindSet distributionBindSet = distributionBindSetService.getById(id);
//		return ResponseEntity.ok(distributionBindSet);
//	}

//	/**
//	 * 删除
//	 */
//	@DeleteMapping("/{id}")
//	@PreAuthorize("@pms.hasPermission('platform:distributionBindSet:delete')")
//	public ResponseEntity<Void> delete(/*@PathVariable Long id*/){
//		DistributionBindSet distributionBindSet = distributionBindSetService.getByShopId(Constant.PLATFORM_SHOP_ID);
//		distributionBindSetService.removeById(distributionBindSet.getBindId());
//		distributionBindSetService.removeCacheByShopId(Constant.PLATFORM_SHOP_ID);
//		return ResponseEntity.ok().build();
//	}
}
