package com.ruoyi.demo.controller;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.demo.entity.Commercial;
import com.ruoyi.demo.entity.vo.CommercialVo;
import com.ruoyi.demo.service.CommericalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/commercial")
public class CommercialController {
    @Autowired
    CommericalService commericalService;

    /**
     * 新增商户
     * @param commercialVo
     * @return
     */
    @PostMapping("/addCommercial")
    public R addCommercial(@RequestBody @Validated(value = {AddGroup.class}) CommercialVo commercialVo){
        commericalService.addCommercial(commercialVo);
        return R.ok();
    }

    @PutMapping("/updateCommercial")
    public R updateCommercial(@RequestBody @Validated(value = {EditGroup.class}) CommercialVo commercialVo){
        commericalService.updateCommercial(commercialVo);
        return R.ok();
    }

    /**
     * 删除商户
     * @param commercialIds
     * @return
     */
    @DeleteMapping("/deleteCommercial")
    public R deleteCommercial(@NotEmpty(message = "待删除商户Id不能为空") String[] commercialIds){
        String s = commericalService.deleteCommercial(commercialIds);
        return R.ok(s);
    }

    /**
     * 获取商户详细信息
     * @param commercialId
     * @return
     */
    @GetMapping("/getCommercial")
    public R getCommercial(@NotBlank(message = "商户Id不能为空") String commercialId){
        Commercial commercial = commericalService.getCommercial(commercialId);
        return R.ok(commercial);
    }

    /**
     * 获取商户列表
     * @param commercialVo
     * @return
     */
    @GetMapping("/getCommercialList")
    public R getCommercialList(CommercialVo commercialVo){
        HashMap commercialList = commericalService.getCommercialList(commercialVo);
        return R.ok(commercialList);
    }

    @GetMapping("/getCommercialName")
    public R getCommercialName(){
        List<Commercial> commercialName = commericalService.getCommercialName();
        return R.ok(commercialName);
    }
}
