package com.ics.admin.controller.meeting;

import com.ics.system.service.ICurrentUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ics.common.core.domain.R;
import com.ics.common.core.controller.BaseController;
import com.ics.admin.domain.meeting.RoomItem;
import com.ics.admin.service.meeting.IRoomItemService;
import org.wf.jwtp.annotation.RequiresPermissions;
import org.wf.jwtp.util.SubjectUtil;

/**
 * 房间物品 提供者
 *
 * @author chen
 * @date 2024-02-23
 */
@RestController
@RequestMapping("/meeting/roomItem")
public class RoomItemController extends BaseController {

    @Autowired
    private IRoomItemService roomItemService;

    @Autowired
    private ICurrentUserService currentUserService;

    /**
     * 查询房间物品
     */
    @GetMapping("get/{id}")
    public RoomItem get(@PathVariable("id") Long id) {
        return roomItemService.selectRoomItemById(id);
    }

    /**
     * 查询房间物品列表
     */
    @RequiresPermissions("meeting:item:list")
    @GetMapping("list")
    public R list(RoomItem roomItem) {
        startPage();
        boolean isAdmin = SubjectUtil.hasRole(getRequest(),"manager");
        if (isAdmin){
            Long parkId = currentUserService.getParkId();
            Long tenantId = currentUserService.getTenantId();
            roomItem.setParkId(parkId);
//            roomItem.setTenantId(tenantId);
        }
        return result(roomItemService.selectRoomItemList(roomItem));
    }


    /**
     * 新增保存房间物品
     */
    @RequiresPermissions("meeting:item:add")
    @PostMapping("save")
    public R addSave(@RequestBody RoomItem roomItem) {
        return toAjax(roomItemService.insertRoomItem(roomItem));
    }

    /**
     * 修改保存房间物品
     */
    @RequiresPermissions("meeting:item:edit")
    @PostMapping("update")
    public R editSave(@RequestBody RoomItem roomItem) {
        return toAjax(roomItemService.updateRoomItem(roomItem));
    }

    /**
     * 删除房间物品
     */
    @RequiresPermissions("meeting:item:remove")
    @PostMapping("remove")
    public R remove(String ids) {
        return toAjax(roomItemService.deleteRoomItemByIds(ids));
    }

}
