package cn.ysk.cashier.controller.shop;

import cn.ysk.cashier.annotation.Log;
import cn.ysk.cashier.dto.shop.TbPlussShopStaffQueryCriteria;
import cn.ysk.cashier.pojo.shop.TbPlussShopStaff;
import cn.ysk.cashier.service.shop.TbPlussShopStaffService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
* @website https://eladmin.vip
* @author lyf
* @date 2024-03-01
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "/shop/shopStaff管理")
@RequestMapping("/api/tbPlussShopStaff")
public class TbPlussShopStaffController {

    private final TbPlussShopStaffService tbPlussShopStaffService;

    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    public void exportTbPlussShopStaff(HttpServletResponse response, TbPlussShopStaffQueryCriteria criteria) throws IOException {
        tbPlussShopStaffService.download(tbPlussShopStaffService.queryAll(criteria), response);
    }

    @GetMapping
    @ApiOperation("查询/shop/shopStaff")
    public ResponseEntity<Object> queryTbPlussShopStaff(TbPlussShopStaffQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(tbPlussShopStaffService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @GetMapping("/{id}")
    @ApiOperation("查询/shop/shopStaff")
    public ResponseEntity<Object> queryShopStaffByid(@PathVariable("id") Integer id){
        return new ResponseEntity<>(tbPlussShopStaffService.findById(id),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增员工:#resources.name")
    @ApiOperation("新增/shop/shopStaff")
    public ResponseEntity<Object> createTbPlussShopStaff(@Validated @RequestBody TbPlussShopStaff resources){
        return new ResponseEntity<>(tbPlussShopStaffService.create(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改员工:#resources.name")
    @ApiOperation("修改/shop/shopStaff")
    public ResponseEntity<Object> updateTbPlussShopStaff(@Validated @RequestBody TbPlussShopStaff resources){
        tbPlussShopStaffService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @PutMapping("updateStatus")
    @Log("修改员工状态:#resources.name")
    @ApiOperation("修改/shop/shopStaff")
    public ResponseEntity<Object> updateStatus(@Validated @RequestBody TbPlussShopStaff resources){
        tbPlussShopStaffService.updateStatus(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除员工:#ids")
    @ApiOperation("删除/shop/shopStaff")
    public ResponseEntity<Object> deleteTbPlussShopStaff(@RequestBody Integer[] ids) {
        tbPlussShopStaffService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

//    @ApiOperation("修改个人密码")
//    @PostMapping(value = "/upPass")
//    @AnonymousPostMapping
//    public ResponseEntity<Object> upshopStaffPass(HttpServletRequest request, @RequestBody Map<String, String> map){
//        tbShopInfoService.upShopPass(map.get("username"),map.get("password"));
//        //根据token踢出用户
//        onlineUserService.logout(tokenProvider.getToken(request));
//        log.info("修改商户密码成功。");
//        return new ResponseEntity<>(HttpStatus.OK);
//    }
}
