package shop.alien.storeplatform.controller;

import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.*;
import shop.alien.entity.result.R;
import shop.alien.storeplatform.entity.StorePlatformStoreStaffConfig;
import shop.alien.storeplatform.service.StorePlatformStoreStaffConfigService;

import java.util.List;

@Slf4j
@Api(tags = {"商户平台-运动健身-人员配置"})
@ApiSort(1)
@CrossOrigin
@RestController
@RequiredArgsConstructor
@RequestMapping("/storeStaffConfig")
public class StorePlatformStoreStaffConfigController {

    private final StorePlatformStoreStaffConfigService staffConfigService;

    @ApiOperation("根据ID查询员工")
    @ApiOperationSupport(order = 1)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "员工ID", dataType = "Integer", paramType = "query", required = true)
    })
    @GetMapping("/getById")
    public R<StorePlatformStoreStaffConfig> getById(@RequestParam("id") Integer id) {
        log.info("StorePlatformStoreStaffConfigController.getById id={}", id);
        StorePlatformStoreStaffConfig staffConfig = staffConfigService.getById(id);
        if (staffConfig == null) {
            return R.fail("员工不存在");
        }
        return R.data(staffConfig);
    }

    @ApiOperation("根据门店ID查询员工列表")
    @ApiOperationSupport(order = 2)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "storeId", value = "门店ID", dataType = "Integer", paramType = "query", required = true)
    })
    @GetMapping("/getListByStoreId")
    public R<List<StorePlatformStoreStaffConfig>> getListByStoreId(@RequestParam("storeId") Integer storeId) {
        log.info("StorePlatformStoreStaffConfigController.getListByStoreId storeId={}", storeId);
        List<StorePlatformStoreStaffConfig> list = staffConfigService.getListByStoreId(storeId);
        return R.data(list);
    }

    @ApiOperation("新增员工")
    @ApiOperationSupport(order = 3)
    @PostMapping("/save")
    public R<String> save(@RequestBody StorePlatformStoreStaffConfig staffConfig) {
        log.info("StorePlatformStoreStaffConfigController.save staffConfig={}", staffConfig);
        return staffConfigService.saveStaff(staffConfig);
    }

    @ApiOperation("修改员工")
    @ApiOperationSupport(order = 4)
    @PostMapping("/update")
    public R<String> update(@RequestBody StorePlatformStoreStaffConfig staffConfig) {
        log.info("StorePlatformStoreStaffConfigController.update staffConfig={}", staffConfig);
        return staffConfigService.updateStaff(staffConfig);
    }

    @ApiOperation("新增或修改员工")
    @ApiOperationSupport(order = 5)
    @PostMapping("/saveOrUpdate")
    public R<String> saveOrUpdate(@RequestBody StorePlatformStoreStaffConfig staffConfig) {
        log.info("StorePlatformStoreStaffConfigController.saveOrUpdate staffConfig={}", staffConfig);
        return staffConfigService.saveOrUpdateStaff(staffConfig);
    }

    @ApiOperation("删除员工")
    @ApiOperationSupport(order = 6)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "员工ID", dataType = "Integer", paramType = "query", required = true)
    })
    @GetMapping("/delete")
    public R<String> delete(@RequestParam("id") Integer id) {
        log.info("StorePlatformStoreStaffConfigController.delete id={}", id);
        return staffConfigService.deleteStaff(id);
    }

    @ApiOperation("批量删除员工")
    @ApiOperationSupport(order = 7)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "员工ID列表", dataType = "List", paramType = "query", required = true)
    })
    @GetMapping("/deleteBatch")
    public R<String> deleteBatch(@RequestParam("ids") List<Integer> ids) {
        log.info("StorePlatformStoreStaffConfigController.deleteBatch ids={}", ids);
        return staffConfigService.deleteStaffBatch(ids);
    }
}
