package com.ycwl.basic.controller.mobile.manage;

import com.github.pagehelper.PageInfo;
import com.ycwl.basic.constant.BaseContextHandler;
import com.ycwl.basic.mapper.ScenicAccountMapper;
import com.ycwl.basic.model.pc.order.req.OrderReqQuery;
import com.ycwl.basic.model.pc.order.resp.OrderRespVO;
import com.ycwl.basic.model.pc.scenic.entity.ScenicAccountEntity;
import com.ycwl.basic.service.pc.OrderService;
import com.ycwl.basic.utils.ApiResponse;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/mobile/scenic/order/v1")
@Api(tags = "景区账号相关接口")
public class AppScenicOrderController {
    @Autowired
    private OrderService orderService;
    @Autowired
    private ScenicAccountMapper scenicAccountMapper;

    @PostMapping("/list")
    public ApiResponse<List<OrderRespVO>> list(@RequestBody OrderReqQuery query) {
        String userId = BaseContextHandler.getUserId();
        ScenicAccountEntity account = scenicAccountMapper.findAccountById(userId);
        if (account == null) {
            return ApiResponse.fail("用户未绑定景区");
        }
        query.setScenicId(account.getScenicId());
        return orderService.list(query);
    }

    @PostMapping("/page")
    public ApiResponse<PageInfo<OrderRespVO>> page(@RequestBody OrderReqQuery query) {
        String userId = BaseContextHandler.getUserId();
        ScenicAccountEntity account = scenicAccountMapper.findAccountById(userId);
        if (account == null) {
            return ApiResponse.fail("用户未绑定景区");
        }
        query.setScenicId(account.getScenicId());
        return orderService.pageQueryDetail(query);
    }
}
