package cn.pluss.platform.controller;

import cn.pluss.platform.api.Result;
import cn.pluss.platform.api.ResultGenerator;
import cn.pluss.platform.dto.MerchantStaffDTO;
import cn.pluss.platform.merchant.MerchantStaffConnService;
import cn.pluss.platform.vo.MerchantStaffVO;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * @author DJH
 */
@RestController
@RequestMapping("/merchantStaff")
public class MerchantStaffController {

    @Setter(onMethod_ = {@Autowired})
    private MerchantStaffConnService connService;

    @PostMapping
    public Result<Object> save(@RequestBody MerchantStaffDTO merchantStaffDTO) {
        connService.createOrEditStaff(merchantStaffDTO);
        return ResultGenerator.genSuccessResult("保存成功", null);
    }

    @GetMapping("/del")
    public Result<Object> remove(Long userId, String merchantCodes) {
        String[] split = merchantCodes.split(",");
        connService.delStaff(userId, Arrays.asList(split.clone()));
        return ResultGenerator.genSuccessResult("删除成功", null);
    }

    @GetMapping("/{userId}")
    public Result<Object> one(@PathVariable("userId") String userId) {
        MerchantStaffVO result = connService.getOneForApp(userId);
        return ResultGenerator.genSuccessResult( result);
    }
}
