package cn.iocoder.yudao.module.inspection.controller;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.module.inspection.entity.InspectionAppointment;
import cn.iocoder.yudao.module.inspection.entity.InspectionGoodsSku;
import cn.iocoder.yudao.module.inspection.entity.InspectionPickCar;
import cn.iocoder.yudao.module.inspection.query.GoodsQuery;
import cn.iocoder.yudao.module.inspection.service.AppInspectionGoodsService;
import cn.iocoder.yudao.module.inspection.service.IInspectionAppointmentService;
import cn.iocoder.yudao.module.inspection.service.InspectionGoodsSkuService;
import cn.iocoder.yudao.module.inspection.vo.GoodsVo;
import cn.iocoder.yudao.module.shop.service.IShopCouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import cn.iocoder.yudao.module.core.controller.BaseController;
import java.util.List;

@RestController
@RequestMapping("/admin-api/appInspection/goods")
public class AppGoodsController extends BaseController {
    @Autowired
    private AppInspectionGoodsService appInspectionGoodsService;
    @Autowired
    private IShopCouponService couponService;
    @Autowired
    private InspectionGoodsSkuService skuService;
    @Autowired
    private IInspectionAppointmentService appointmentService;

    /**
     * 分类列表查询
     */
    @GetMapping("/categoryList")
    @TenantIgnore
    public CommonResult categoryList()
    {
        return  success(appInspectionGoodsService.categoryList());
    }

    /**
     * 商品列表查询
     */
    @GetMapping("/list")
    public CommonResult goodsList(GoodsQuery goodsQuery)
    {
        List<GoodsVo> list = appInspectionGoodsService.goodsList(goodsQuery);
        return success(list);
    }

    /**
     * 获取商品详情
     */
    @GetMapping("/goodsDetail")
    public CommonResult goodsDetail(GoodsQuery goodsQuery)
    {
        return   success(appInspectionGoodsService.goodsDetail(goodsQuery));
    }
    /**
     * 获取商品规格
     */
    @GetMapping("/goodsSkuList")
    public CommonResult goodsSkuList(GoodsQuery goodsQuery)
    {
        return   success(appInspectionGoodsService.goodsSkuList(goodsQuery));
    }

    /**
     * 下单页信息返回
     */
    @GetMapping("/orderGoodsInfo")
    public CommonResult orderGoodsInfo(GoodsQuery goodsQuery)
    {
        return   success(appInspectionGoodsService.orderGoodsInfo(goodsQuery));
    }

    /**
     * 下单页信息返回
     */
    @GetMapping("/orderSkuInfo")
    public CommonResult orderSkuInfo(GoodsQuery goodsQuery)
    {
        return   success(appInspectionGoodsService.orderSkuInfo(goodsQuery));
    }
    /**
     * 下单页信息返回
     */
    @GetMapping("/canUseCoupon")
    public CommonResult canUseCoupon(Integer objectId,String type)
    {
        Integer goodsId =objectId;
        if (type.equals("sku")){
            InspectionGoodsSku sku = skuService.getById(objectId);
            goodsId=sku.getGoodsId() ;
        }
        return   success(couponService.canUseCoupon(goodsId,"检测项目现金券"));
    }
    /**
     * 预约功能
     */
    @GetMapping("/appointmentDateList")
    public CommonResult appointmentDateList(Long goodsId,String type)
    {
        return success(appointmentService.appointmentDateList(goodsId,type));
    }

    /**
     * 上门取车功能
     */
    @GetMapping("/pickCarInfo")
    public CommonResult pickCarInfo()
    {
        return success(appointmentService.pickCarInfo());
    }

    /**
     * 根据经纬度计算距离和价格
     */
    @GetMapping("/computeDistanceAndPrice")
    public CommonResult computeDistanceAndPrice(Long goodsId,Double longitude,Double latitude,String type ) throws Exception {
        return success(appointmentService.computeDistanceAndPrice(goodsId,longitude,latitude,type));
    }
    /**
     * 预约功能
     */
    @PostMapping("/appointmentInspection")
    public CommonResult appointmentInspection(@RequestBody InspectionAppointment appointment)
    {
       return success(appointmentService.appointmentInspection(appointment));
    }
    /**
     * 修改预约功能
     */
    @PostMapping("/editAppointment")
    public CommonResult editAppointment(@RequestBody InspectionAppointment appointment)
    {
        return success(appointmentService.editAppointment(appointment));
    }

    /**
     * 删除预约信息
     */
    @PostMapping("/delAppointment")
    public CommonResult delAppointment(@RequestParam("appointmentId") Long appointmentId)
    {
        appointmentService.delAppointment(appointmentId);
        return success();
    }
    /**
     * 上门取车
     */
    @PostMapping("/pickCarInspection")
    public CommonResult pickCarInspection(@RequestBody InspectionPickCar pickCar) throws Exception {
        return success(appointmentService.pickCarInspection(pickCar));
    }
    /**
     * 进店获取可领取的优惠券
     */
    @GetMapping("/canLedCoupon")
    public CommonResult canLedCoupon(Long partnerId)
    {
        return success(couponService.canLedCoupon(partnerId));
    }
    @PostMapping("/drawDownCoupon")
    public CommonResult drawDownCoupon(Long partnerId)
    {
        couponService.drawDownCoupon(partnerId);
        return success();
    }

    /**
     * 平台赠送的可以领取的优惠券
     */
    @GetMapping("/canLedCouponPlatform")
    public CommonResult canLedCouponPlatform()
    {
        return success(couponService.canLedCouponPlatform());
    }
    @PostMapping("/drawDownCouponPlatform")
    public CommonResult drawDownCouponPlatform()
    {
        couponService.drawDownCouponPlatform();
        return success();
    }
}
