package cn.ysk.cashier.controller.shop;

import cn.ysk.cashier.annotation.Log;
import cn.ysk.cashier.dto.shop.TbShopPermissionDto;
import cn.ysk.cashier.service.TbShopPermissionService;
import cn.ysk.cashier.service.TbShopStaffPermissionService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequiredArgsConstructor
@Api(tags = "歌曲管理")
@RequestMapping("/api/tbShopPermission")
public class TbShopPermissionController {
    private final TbShopPermissionService shopPermissionService;

    private final TbShopStaffPermissionService shopStaffPermissionService;

    @PostMapping()
    @Log("新增店铺权限:#permissionDto.label")
    public ResponseEntity<Object> insertShopPermission(@RequestBody TbShopPermissionDto permissionDto) {
        return shopPermissionService.insert(permissionDto);
    }

    @PutMapping()
    @Log("修改店铺权限:#permissionDto.label")
    public ResponseEntity<Object> updateShopPermission(@RequestBody TbShopPermissionDto permissionDto) {
        return shopPermissionService.update(permissionDto);
    }

    @DeleteMapping("/{id}")
    @Log("删除店铺权限:#id")
    public ResponseEntity<Object> deleteShopPermission(@PathVariable Integer id) {
        return shopPermissionService.delete(id);
    }

    @GetMapping("/list")
    public ResponseEntity<Object> getShopPermissionList() {
        List<TbShopPermissionDto> permissionList = shopPermissionService.getShopPermissionList();
        return ResponseEntity.ok(permissionList);
    }

    @GetMapping("/hasPermission")
    public ResponseEntity<Object> hasPermission(Integer userId, String code) {
        boolean hasPermission = shopStaffPermissionService.userHasPermission(userId, code);
        return ResponseEntity.ok(hasPermission);
    }

    @GetMapping("/staffPermissionList")
    public ResponseEntity<Object> getStaffPermissionList(Integer userId) {
        return ResponseEntity.ok(shopStaffPermissionService.getStaffPermissionList(userId));
    }
}
