package com.gree.mall.miniapp.controller.material.parts;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gree.mall.miniapp.bean.material.parts.WebsitExtends;
import com.gree.mall.miniapp.exception.RemoteServiceException;
import com.gree.mall.miniapp.helper.ResponseHelper;
import com.gree.mall.miniapp.logic.material.parts.BuyLogic;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Slf4j
@RestController
@Api(value = "配件购买", tags ={"配件购买"} )
@RequestMapping(value = "/app/buy", produces = "application/json; charset=utf-8")
public class BuyController {

    @Resource
    BuyLogic buyLogic;

    @ApiOperation(value = "当前默认销售网点")
    @PostMapping("/websit/default")
    public ResponseHelper<WebsitExtends> websitDefault(
            @ApiParam(value = "所属网点编码",required = false) @RequestParam(required = false)  String websitId,
            @ApiParam(value = "经度",required = true) @RequestParam(required = true) String longitude,
            @ApiParam(value = "纬度",required = true) @RequestParam(required = true) String latitude
    ) throws RemoteServiceException {
        WebsitExtends shop = buyLogic.defaultWebsit(websitId, longitude, latitude);
        return ResponseHelper.success(shop);
    }


    @ApiOperation(value = "附近的销售网点列表")
    @PostMapping("/websit/list")
    public ResponseHelper<IPage<WebsitExtends>> websitDefault(
            @ApiParam(value = "所属网点编码") @RequestParam(required = false) String websitId,
            @ApiParam(value = "经度",required = true) @RequestParam String longitude,
            @ApiParam(value = "纬度",required = true) @RequestParam String latitude,
            @ApiParam(value = "页号",required = true) @RequestParam Integer pageNo,
            @ApiParam(value = "页大小",required = true) @RequestParam Integer pageSize
    ) throws RemoteServiceException {
        IPage<WebsitExtends> fcShopExtendsIPage = buyLogic.queryWebsitList(websitId, longitude, latitude, pageNo, pageSize);
        return ResponseHelper.success(fcShopExtendsIPage);
    }
}
