package com.tourism.webadmin.app.website.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import com.github.pagehelper.page.PageMethod;
import com.tourism.common.core.constant.ErrorCodeEnum;
import com.tourism.common.core.object.MyOrderParam;
import com.tourism.common.core.object.MyPageData;
import com.tourism.common.core.object.ResponseResult;
import com.tourism.common.core.util.MyModelUtil;
import com.tourism.common.core.util.MyPageUtil;
import com.tourism.webadmin.app.website.dto.TourProjectGroupPurchaseDetailDtoToWebDto;
import com.tourism.webadmin.back.model.TourProjectGroupPurchaseDetail;
import com.tourism.webadmin.back.service.TourProjectGroupPurchaseDetailService;
import com.tourism.webadmin.back.vo.TourProjectGroupPurchaseDetailVo;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 拼团设置从表操作控制器类。
 *
 * @author 吃饭睡觉
 * @date 2024-09-06
 */
@Tag(name = "拼团设置从表管理接口")
@Slf4j
@RestController
@RequestMapping("/website/app/tourProjectGroupPurchaseDetail")
public class WebsiteProjectGroupPurchaseDetailController {

    @Autowired
    private TourProjectGroupPurchaseDetailService tourProjectGroupPurchaseDetailService;


    /**
     * 阶梯价格接口。
     *
     * @param dto 过滤对象。
     * @return 应答结果对象，包含查询结果集。
     */
    @SaIgnore
    @GetMapping("/list")
    public ResponseResult<MyPageData<TourProjectGroupPurchaseDetailVo>> list(TourProjectGroupPurchaseDetailDtoToWebDto dto) {
        if (dto != null) {
            PageMethod.startPage(dto.getPageNum(), dto.getPageSize(), dto.getCount());
        }
        if(dto.getGroupPurchaseCode() == null) {
            return ResponseResult.error(ErrorCodeEnum.MISS_PROJECT_ID);
        }
        TourProjectGroupPurchaseDetail tourProjectGroupPurchaseDetailFilter = MyModelUtil.copyTo(dto, TourProjectGroupPurchaseDetail.class);
        MyOrderParam myOrderParam = new MyOrderParam();
        myOrderParam.add(new MyOrderParam.OrderInfo("minCount",true,null));
        String orderBy = MyOrderParam.buildOrderBy(myOrderParam, TourProjectGroupPurchaseDetail.class);
        List<TourProjectGroupPurchaseDetail> tourProjectGroupPurchaseDetailList =
                tourProjectGroupPurchaseDetailService.getTourProjectGroupPurchaseDetailListWithRelation(tourProjectGroupPurchaseDetailFilter, null, orderBy);
        return ResponseResult.success(MyPageUtil.makeResponseData(tourProjectGroupPurchaseDetailList, TourProjectGroupPurchaseDetailVo.class));
    }
}
