package com.jeequan.jeepay.mgr.ctrl.alipay;

import com.jeequan.jeepay.bizcommons.manage.alipay.AlipayShopManage;
import com.jeequan.jeepay.core.entity.MchStore;
import com.jeequan.jeepay.core.model.ApiRes;
import com.jeequan.jeepay.mgr.ctrl.CommonCtrl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/***
* 蚂蚁门店ctrl
*
* @author zx
*
* @date 2023/03/13 15:26
*/
@RestController
@RequestMapping("/api/alipayShop")
public class AlipayShopController extends CommonCtrl {

    @Autowired private AlipayShopManage alipayShopManage;

    /** 查询店铺详情  **/
    @PreAuthorize("hasAnyAuthority('ENT_MCH_ALIPAY_SHOP_VIEW', 'ENT_MCH_ALIPAY_SHOP_EDIT')")
    @GetMapping( "/{storeId}")
    public ApiRes query(@PathVariable("storeId") String storeId) {
        return alipayShopManage.query(null, storeId);
    }

    /** 创建店铺  **/
    @PreAuthorize("hasAuthority('ENT_MCH_ALIPAY_SHOP_ADD')")
    @PostMapping("/{storeId}")
    public ApiRes create(@PathVariable("storeId") String storeId) {
        MchStore mchStore = getObject(MchStore.class);
        return alipayShopManage.create(null, storeId, mchStore);
    }

    /** 修改店铺  **/
    @PreAuthorize("hasAuthority('ENT_MCH_ALIPAY_SHOP_EDIT')")
    @PutMapping("/{storeId}")
    public ApiRes update(@PathVariable("storeId") String storeId) {
        MchStore mchStore = getObject(MchStore.class);
        return alipayShopManage.update(null, storeId, mchStore);
    }

    /** 关闭店铺  **/
    @PreAuthorize("hasAuthority('ENT_MCH_ALIPAY_SHOP_DELETE')")
    @DeleteMapping( "/{storeId}")
    public ApiRes close(@PathVariable("storeId") String storeId) {
        return alipayShopManage.close(null, storeId);
    }

    /** 根据申请单查询店铺创建结果  **/
    @PreAuthorize("hasAuthority('ENT_MCH_ALIPAY_SHOP_STATUS')")
    @GetMapping("/createResult/{storeId}")
    public ApiRes createResultQuery(@PathVariable("storeId") String storeId) {
        return alipayShopManage.createResultQuery(null, storeId);
    }

}
