package com.nmgs.controller;

import com.nmgs.config.ResultData;
import com.nmgs.service.IServiceAreaService;
import com.nmgs.service.impl.ServiceAreaServiceImpl;
import com.nmgs.util.PubTools;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value="serviceArea")
@Api(tags="服务区管理")
public class ServiceAreaController {
    public IServiceAreaService iServiceAreaService ;
    @Autowired
    public void setiServiceAreaService(IServiceAreaService iServiceAreaService) {
        this.iServiceAreaService = iServiceAreaService;
    }

    @ApiOperation(value="查询服务区列表数据",httpMethod = "POST")
    @RequestMapping(value = "getAreaList",
            method = {RequestMethod.POST}
    )
    public ResultData<List> getAreaList(@RequestParam(value = "areaName",required = false) String areaName,
                                        @RequestParam(value = "areaScope",required = false) String areaScope,
                                        @RequestParam(value = "showPic",required = false) String showPic,
                                        @RequestParam(value = "pageSize",required = true) String pageSize,
                                        @RequestParam(value = "currentPage",required = true) String currentPage){
        int start=0;
        int end=1000000000;
        List userByOpenId =null;
        List totalList =null;
        if(!PubTools.isNull(pageSize) && !PubTools.isNull(currentPage)){
            start=(Integer.parseInt(currentPage)-1)* Integer.parseInt(pageSize)+1;
            end=Integer.parseInt(currentPage)*Integer.parseInt(pageSize);
            userByOpenId = iServiceAreaService.getServiceAreaList(areaName,areaScope,showPic,start,end);
            totalList = iServiceAreaService.getServiceAreaList(areaName,areaScope,showPic,0,0);
        }else{
            userByOpenId = iServiceAreaService.getServiceAreaList(areaName,areaScope,showPic,start,end);
            totalList=userByOpenId;
        }
        if(userByOpenId != null){
            return ResultData.success("查询成功",userByOpenId,totalList.size());
        }else{
            return ResultData.fail("查询失败");
        }


    }

    @ApiOperation(value="查询服务区详情数据",httpMethod = "POST")
    @RequestMapping(value = "getAreaDetailList",
            method = {RequestMethod.POST}
    )
    public ResultData<List> getAreaDetailList(@RequestParam("serviceId") String serviceId){
        List userByOpenId = iServiceAreaService.getServiceAreaDetail(serviceId);
        if(userByOpenId ==null ){
            return ResultData.fail("查询失败");
        }else if(userByOpenId !=null){
            return ResultData.success("查询成功",userByOpenId,userByOpenId.size());
        }
        return ResultData.success(1,"查询成功");
    }

    @ApiOperation(value="查询服务区中各商户餐饮套餐数据",httpMethod = "POST")
    @RequestMapping(value = "getAreaMealList",
            method = {RequestMethod.POST}
    )
    public ResultData<List> getAreaMealList(@RequestParam(value = "operatorId",required = false) String operatorId,
                                            @RequestParam("areaId") String areaId,
                                            @RequestParam(value = "ids",required = false) String ids){
        List userByOpenId = iServiceAreaService.getAreaMealList(operatorId,areaId,ids);
        if(userByOpenId ==null ){
            return ResultData.fail("查询失败");
        }else if(userByOpenId !=null){
            return ResultData.success("查询成功",userByOpenId,userByOpenId.size());
        }
        return ResultData.success(1,"查询成功");
    }
}
