package com.czg.controller.admin;

import com.czg.account.dto.extend.ShopExtendDTO;
import com.czg.account.entity.ShopExtend;
import com.czg.account.service.ShopExtendService;
import com.czg.annotation.SaAdminCheckPermission;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 店铺拓展配置/装修
 *
 * @author Administrator
 */
@RestController
@RequestMapping("/admin/shopExtend")
public class ShopExtendController {
    @Resource
    private ShopExtendService shopExtendService;

    /**
     * 获取当前店铺拓展参数
     *
     * @param autoKey key名称
     * @return 参数列表
     */
    @SaAdminCheckPermission(parentName = "店铺拓展参数", value = "shopExtend:list", name = "店铺拓展参数列表")
    @GetMapping
    public CzgResult<List<ShopExtend>> list(String autoKey) {
        return CzgResult.success(shopExtendService.listInfo(StpKit.USER.getShopId(), autoKey));
    }

    /**
     * 获取当前店铺拓展参数详情
     *
     * @param autoKey key名称 小票logo ticket_logo
     * @return 详细信息
     */
    @SaAdminCheckPermission(parentName = "店铺拓展参数", value = "shopExtend:detail", name = "店铺拓展参数详情")
    @GetMapping("/detail")
    public CzgResult<ShopExtend> detail(@RequestParam String autoKey) {
        return CzgResult.success(shopExtendService.getOne(new QueryWrapper().eq(ShopExtend::getShopId, StpKit.USER.getShopId()).eq(ShopExtend::getAutoKey, autoKey)));
    }

    /**
     * 店铺拓展参数修改
     *
     * @return 是否成功
     */
    @SaAdminCheckPermission(parentName = "店铺拓展参数", value = "shopExtend:edit", name = "店铺拓展参数修改")
    @PutMapping
    public CzgResult<Boolean> edit(@RequestBody @Validated ShopExtendDTO shopExtendDTO) {
        return CzgResult.success(shopExtendService.edit(StpKit.USER.getShopId(), shopExtendDTO));
    }
}
