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

import cn.dev33.satoken.annotation.SaIgnore;
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.MyPageUtil;
import com.tourism.webadmin.back.model.BannerInfo;
import com.tourism.webadmin.back.model.CompanyInfo;
import com.tourism.webadmin.back.model.DirectoryInfo;
import com.tourism.webadmin.back.service.BannerInfoService;
import com.tourism.webadmin.back.service.CompanyInfoService;
import com.tourism.webadmin.back.service.DirectoryInfoService;
import com.tourism.webadmin.back.vo.BannerInfoVo;
import com.tourism.webadmin.back.vo.CompanyInfoVo;
import com.tourism.webadmin.back.vo.DirectoryInfoVo;
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.*;

import java.util.List;

@Tag(name = "提供网页基础信息")
@Slf4j
@RestController
@SaIgnore
@RequestMapping("/website/basic")
public class BasicToWebController {

    @Autowired
    private BannerInfoService bannerInfoService;
    @Autowired
    private CompanyInfoService companyInfoService;
    @Autowired
    private DirectoryInfoService directoryInfoService;

    /**
     * 列出符合过滤条件的banner管理列表。
     * @return 应答结果对象，包含查询结果集。
     */
    @GetMapping("/bannerList")
    public ResponseResult<MyPageData<BannerInfoVo>> bannerInfoList(@RequestParam("belongTab") Long belongTab) {
        BannerInfo bannerInfoFilter = new BannerInfo();
        bannerInfoFilter.setBelongTab(belongTab);
        String orderBy = MyOrderParam.buildOrderBy(new MyOrderParam(), BannerInfo.class);
        List<BannerInfo> bannerInfoList = bannerInfoService.getBannerInfoListWithRelation(bannerInfoFilter, orderBy);
        return ResponseResult.success(MyPageUtil.makeResponseData(bannerInfoList, BannerInfoVo.class));
    }

    /**
     * 列出符合过滤条件的门户菜单管理列表。
     * @return 应答结果对象，包含查询结果集。
     */
    @GetMapping("/directoryList")
    public ResponseResult<MyPageData<DirectoryInfoVo>> directoryInfoList(@RequestParam("parentId") Long parentId) {
//        if (ObjectUtils.isEmpty(parentId)){
//            return ResponseResult.error("NO-ERROR","父级Id为空");
//        }
        DirectoryInfo directoryInfoFilter = new DirectoryInfo();
        directoryInfoFilter.setParentId(parentId);
        String orderBy = MyOrderParam.buildOrderBy(new MyOrderParam(), DirectoryInfo.class);
        List<DirectoryInfo> directoryInfoList =
                directoryInfoService.getDirectoryInfoListWithRelation(directoryInfoFilter, orderBy);
        return ResponseResult.success(MyPageUtil.makeResponseData(directoryInfoList, DirectoryInfoVo.class));
    }

    /**
     * 列出符合过滤条件的公司信息管理列表。
     *  @return 应答结果对象，包含查询结果集。
     */
    @GetMapping("/companyList")
    public ResponseResult<MyPageData<CompanyInfoVo>> companyInfoList(@RequestParam("companyType") Integer companyType) {
        CompanyInfo companyInfoFilter = new CompanyInfo();
        companyInfoFilter.setCompanyType(companyType);
        String orderBy = MyOrderParam.buildOrderBy(new MyOrderParam(), CompanyInfo.class);
        List<CompanyInfo> companyInfoList =
                companyInfoService.getCompanyInfoListWithRelation(companyInfoFilter, orderBy);
        return ResponseResult.success(MyPageUtil.makeResponseData(companyInfoList, CompanyInfoVo.class));
    }
}
