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

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.security.core.LoginUser;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.module.core.page.PageDomain;
import cn.iocoder.yudao.module.core.page.TableSupport;
import cn.iocoder.yudao.module.inspection.service.AppUserOwnService;
import cn.iocoder.yudao.module.inspection.service.IInspectionAppointmentService;
import cn.iocoder.yudao.module.payment.entity.OrderInfo;
import cn.iocoder.yudao.module.payment.service.OrderInfoService;
import cn.iocoder.yudao.module.shop.entity.ShopCoupon;
import cn.iocoder.yudao.module.shop.service.IShopCouponService;
import cn.iocoder.yudao.module.shop.service.IShopUserCarService;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@RestController
@RequestMapping("/appInspection/userOwn")
public class AppUserInfoController {

    @Autowired
    private AppUserOwnService ownService;

    @Autowired
    private IShopUserCarService shopUserCarService;

    @Autowired
    private OrderInfoService orderInfoService;

    @Autowired
    private IInspectionAppointmentService inspectionAppointmentService;

    @Autowired
    private IShopCouponService shopCouponService;

    @GetMapping("/getCars")
    @TenantIgnore
    public CommonResult getCars()
    {
        return   success(ownService.getCars());
    }

    @GetMapping("/getDbList")
    @TenantIgnore
    public CommonResult getDbList(String searchValue,
                                  @RequestParam(value = "pageNum" ,required = false ,defaultValue = "1") Integer pageNum,
                                  @RequestParam(value ="pageSize" ,required = false ,defaultValue = "10") Integer pageSize)
    {
        Page<AdminUserDO> page = new Page<>(pageNum, pageSize);
        IPage<AdminUserDO> dbList = ownService.getDbListTow(page,searchValue);
        return success(dbList);
    }

    @GetMapping(value = "/getUserCar")
    @TenantIgnore
    public CommonResult getUserCarByUserId()
    {
        //当前登录用户
        LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
        return success(shopUserCarService.selectShopUserCarByUserId(loginUser.getId()));
    }

    @GetMapping("/orderList")
    @TenantIgnore
    public CommonResult orderList(String status, String title,
                                  @RequestParam(value = "pageNum" ,required = false ,defaultValue = "1") Integer pageNum,
                                  @RequestParam(value ="pageSize" ,required = false ,defaultValue = "10") Integer pageSize) {
        Page<OrderInfo> page = new Page<>(pageNum, pageSize);
        IPage<OrderInfo> orderInfos = orderInfoService.orderListApp(page, status, title, "jc");
        return success(orderInfos);
    }

    @GetMapping("/getAppointmentOwn")
    @TenantIgnore
    public CommonResult getAppointmentOwn()
    {
        return success(inspectionAppointmentService.getAppointmentOwn());
    }

    @GetMapping(value = "/getDetail")
    @TenantIgnore
    public CommonResult getDetail(@RequestParam("id") Long id)
    {
        return success(inspectionAppointmentService.getById(id));
    }

    @GetMapping("/getInfoCard")
    @TenantIgnore
    public CommonResult getInfoCard()
    {
        return success( shopUserCarService.getInfoCard());
    }

    @PostMapping("/infoCardOCR")
    @TenantIgnore
    public CommonResult infoCardOCR(String imagePath) throws Exception
    {
        shopUserCarService.infoCardOCR(imagePath);
        return success(true);
    }

    @GetMapping(value = "/listByUserId")
    @TenantIgnore
    public CommonResult listByUserId(ShopCoupon shopCoupon,
                                     @RequestParam(value = "pageNum" ,required = false ,defaultValue = "1") Integer pageNum,
                                     @RequestParam(value ="pageSize" ,required = false ,defaultValue = "10") Integer pageSize)
    {
        shopCoupon.setUserId(SecurityFrameworkUtils.getLoginUserId());
        PageDomain pageDomain = TableSupport.getPageDomain();
        Page<ShopCoupon> page = new Page<>(pageNum, pageSize);
        IPage<ShopCoupon> list = shopCouponService.selectShopCouponByUserId(page,shopCoupon);
        return success(list);
    }
}
