package com.czg.controller.admin;

import com.czg.account.dto.area.ShopAreaAddDTO;
import com.czg.account.dto.area.ShopAreaEditDTO;
import com.czg.account.entity.ShopTableArea;
import com.czg.account.service.ShopTableAreaService;
import com.czg.annotation.SaAdminCheckPermission;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 区域管理
 * @author Administrator
 */
@RestController
@RequestMapping("/admin/shopArea")
public class ShopTableAreaController {
    @Resource
    private ShopTableAreaService shopTableAreaService;

    /**
     * 区域获取
     * 权限标识: shopArea:add
     * @param name 区域名称
     * @return 是否成功
     */
    @SaAdminCheckPermission(parentName = "区域管理", value = "shopArea:list", name = "区域列表")
    @GetMapping
    public CzgResult<Page<ShopTableArea>> list(String name) {
        return CzgResult.success(shopTableAreaService.pageInfo(StpKit.USER.getShopId(), name));
    }

    /**
     * 区域修改
     * 权限标识: shopArea:edit
     * @return 是否成功
     */
    @SaAdminCheckPermission(parentName = "区域管理", value = "shopArea:edit", name = "区域修改")
    @PutMapping
    public CzgResult<Boolean> edit(@RequestBody @Validated ShopAreaEditDTO shopAreaEditDTO) {
        return CzgResult.success(shopTableAreaService.edit(StpKit.USER.getShopId(), shopAreaEditDTO));
    }

    /**
     * 区域删除
     * 权限标识: shopArea:del
     * @return 是否成功
     */
    @SaAdminCheckPermission(parentName = "区域管理", value = "shopArea:del", name = "区域删除")
    @DeleteMapping
    public CzgResult<Boolean> remove(@RequestBody @Validated ShopAreaEditDTO shopAreaEditDTO) {
        return CzgResult.success(shopTableAreaService.remove(new QueryWrapper().eq(ShopTableArea::getShopId, StpKit.USER.getShopId()).eq(ShopTableArea::getId, shopAreaEditDTO.getId())));
    }

    /**
     * 区域新增
     * 权限标识: shopArea:add
     * @return 是否成功
     */
    @SaAdminCheckPermission(parentName = "区域管理", value = "shopArea:add", name = "区域新增")
    @PostMapping
    public CzgResult<Boolean> add(@RequestBody @Validated ShopAreaAddDTO shopAreaAddDTO) {
        return CzgResult.success(shopTableAreaService.add(shopAreaAddDTO));
    }
}
