package com.zhiqiyun.open.router.apis;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dliyun.oap.framework.annotation.ServiceMethod;
import com.dliyun.oap.framework.annotation.ServiceMethodBean;
import com.dliyun.oap.framework.response.OapResponse;
import com.zhiqiyun.open.core.models.bz.*;
import com.zhiqiyun.open.core.service.*;
import com.zhiqiyun.open.router.request.bz.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

@Slf4j
@ServiceMethodBean
public class BzApi {

    @Autowired
    private HolidayVillageInfoService holidayVillageInfoService;

    @Autowired
    private VenueInfoService venueInfoService;

    @Autowired
    private SceneryInfoService sceneryInfoService;

    @Autowired
    private HotelInfoService hotelInfoService;

    @Autowired
    private HomeStayInfoService homeStayInfoService;

    @Autowired
    private TouristInfoService touristInfoService;

    @ServiceMethod(method = "bz.list.page.venue.info", title = "场馆信息")
    public OapResponse listPageVenueInfo(VenueInfoRequest request) {
        QueryWrapper<VenueInfo> queryWrapper = new QueryWrapper<>();

        if (StringUtils.isNotBlank(request.getKeyword())) {
            queryWrapper.and(true, wrapper -> {
                wrapper.like("name", request.getKeyword());
                wrapper.or();
                wrapper.like("brief", request.getKeyword());
                wrapper.or();
                wrapper.like("address", request.getKeyword());
                wrapper.or();
                wrapper.like("contacts", request.getKeyword());
            });
        }

        Page<VenueInfo> page = new Page<>(request.getCurrent(), request.getSize());
        page.addOrder(OrderItem.desc("id"));

        Page<VenueInfo> resultData = this.venueInfoService.page(page, queryWrapper);

        return OapResponse.success().setBody(resultData);
    }

    @ServiceMethod(method = "bz.list.page.scenery.info", title = "酒店信息")
    public OapResponse listPageSceneryInfo(SceneryInfoRequest request) {
        QueryWrapper<SceneryInfo> queryWrapper = new QueryWrapper<>();

        if (StringUtils.isNotBlank(request.getKeyword())) {
            queryWrapper.and(true, wrapper -> {
                wrapper.like("name", request.getKeyword());
                wrapper.or();
                wrapper.like("brief", request.getKeyword());
                wrapper.or();
                wrapper.like("address", request.getKeyword());
                wrapper.or();
                wrapper.like("contacts", request.getKeyword());
            });
        }

        Page<SceneryInfo> page = new Page<>(request.getCurrent(), request.getSize());
        page.addOrder(OrderItem.desc("id"));

        Page<SceneryInfo> resultData = this.sceneryInfoService.page(page, queryWrapper);

        return OapResponse.success().setBody(resultData);
    }

    @ServiceMethod(method = "bz.list.page.holiday.village.info", title = "查询度假村信息")
    public OapResponse listPageHolidayVillageInfo(HolidayVillageInfoRequest request) {
        QueryWrapper<HolidayVillageInfo> queryWrapper = new QueryWrapper<>();

        if (StringUtils.isNotBlank(request.getKeyword())) {
            queryWrapper.and(true, wrapper -> {
                wrapper.like("name", request.getKeyword());
                wrapper.or();
                wrapper.like("brief", request.getKeyword());
                wrapper.or();
                wrapper.like("address", request.getKeyword());
                wrapper.or();
                wrapper.like("contacts", request.getKeyword());
            });
        }

        Page<HolidayVillageInfo> page = new Page<>(request.getCurrent(), request.getSize());
        page.addOrder(OrderItem.desc("id"));

        Page<HolidayVillageInfo> resultData = this.holidayVillageInfoService.page(page, queryWrapper);

        return OapResponse.success().setBody(resultData);
    }

    @ServiceMethod(method = "bz.list.page.hotel.info", title = "查询酒店信息")
    public OapResponse listPageHotelInfo(HotelInfoRequest request) {
        QueryWrapper<HotelInfo> queryWrapper = new QueryWrapper<>();

        if (StringUtils.isNotBlank(request.getKeyword())) {
            queryWrapper.and(true, wrapper -> {
                wrapper.like("name", request.getKeyword());
                wrapper.or();
                wrapper.like("brief", request.getKeyword());
                wrapper.or();
                wrapper.like("address", request.getKeyword());
                wrapper.or();
                wrapper.like("contacts", request.getKeyword());
            });
        }

        Page<HotelInfo> page = new Page<>(request.getCurrent(), request.getSize());
        page.addOrder(OrderItem.desc("id"));

        Page<HotelInfo> resultData = this.hotelInfoService.page(page, queryWrapper);

        return OapResponse.success().setBody(resultData);
    }

    @ServiceMethod(method = "bz.list.page.home.stay.info", title = "查询酒店信息")
    public OapResponse listPageHomeStayInfo(HomeStayRequest request) {
        QueryWrapper<HomeStayInfo> queryWrapper = new QueryWrapper<>();

        if (StringUtils.isNotBlank(request.getKeyword())) {
            queryWrapper.and(true, wrapper -> {
                wrapper.like("name", request.getKeyword());
                wrapper.or();
                wrapper.like("brief", request.getKeyword());
                wrapper.or();
                wrapper.like("address", request.getKeyword());
                wrapper.or();
                wrapper.like("contacts", request.getKeyword());
            });
        }

        Page<HomeStayInfo> page = new Page<>(request.getCurrent(), request.getSize());
        page.addOrder(OrderItem.desc("id"));

        Page<HomeStayInfo> resultData = this.homeStayInfoService.page(page, queryWrapper);

        return OapResponse.success().setBody(resultData);
    }

    @ServiceMethod(method = "bz.list.page.tourist.info", title = "查询酒店信息")
    public OapResponse listPageTouristInfo(TouristRequest request) {
        QueryWrapper<TouristInfo> queryWrapper = new QueryWrapper<>();

        if (StringUtils.isNotBlank(request.getKeyword())) {
            queryWrapper.and(true, wrapper -> {
                wrapper.like("name", request.getKeyword());
                wrapper.or();
                wrapper.like("brief", request.getKeyword());
                wrapper.or();
                wrapper.like("address", request.getKeyword());
                wrapper.or();
                wrapper.like("contacts", request.getKeyword());
            });
        }

        Page<TouristInfo> page = new Page<>(request.getCurrent(), request.getSize());
        page.addOrder(OrderItem.desc("id"));

        Page<TouristInfo> resultData = this.touristInfoService.page(page, queryWrapper);

        return OapResponse.success().setBody(resultData);
    }
}
