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

import cn.dev33.satoken.annotation.SaIgnore;
import com.tourism.common.core.constant.ErrorCodeEnum;
import com.tourism.common.core.object.MyPageData;
import com.tourism.common.core.object.ResponseResult;
import com.tourism.common.core.util.MyCommonUtil;
import com.tourism.common.core.util.MyPageUtil;
import com.tourism.common.core.validator.AddGroup;
import com.tourism.common.core.validator.UpdateGroup;
import com.tourism.common.log.annotation.OperationLog;
import com.tourism.common.log.model.constant.SysOperationLogType;
import com.tourism.webadmin.app.website.dto.TourismBannerDto;
import com.tourism.webadmin.app.website.service.BasicToWebService;
import com.tourism.webadmin.back.model.TourBusinessBanner;
import com.tourism.webadmin.back.vo.BannerInfoVo;
import com.tourism.webadmin.back.vo.DirectoryInfoVo;
import com.tourism.webadmin.back.vo.TourBusinessBannerVo;
import com.tourism.webadmin.back.vo.TourTourismProjectTravelNotesVo;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.groups.Default;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "门户网站基础信息接口")
@Slf4j
@RestController
@SaIgnore
@Validated
@ConditionalOnProperty(name = "common-online.operationEnabled", havingValue = "true")
@RequestMapping("/website/basic")
public class BasicToWebController {

    @Autowired
    private BasicToWebService basicToWebServicel;

    /**
     * 列出符合过滤条件的banner管理列表。
     * @return 应答结果对象，包含查询结果集。
     */
    @OperationLog(type = SysOperationLogType.LIST)
    @GetMapping("/bannerList")
    public ResponseResult<MyPageData<BannerInfoVo>> bannerInfoList(TourismBannerDto tourismBannerDto) {
        String errorMessage = MyCommonUtil.getModelValidationError(tourismBannerDto, Default.class, UpdateGroup.class);
        if (errorMessage != null) {
            return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATED_FAILED, errorMessage);
        }

        MyPageData<BannerInfoVo> bannerInfoVoMyPageData = basicToWebServicel.getBannerInfoList(tourismBannerDto);
        return ResponseResult.success(bannerInfoVoMyPageData);
    }

    /**
     * 列出符合过滤条件的门户菜单管理列表。
     * @return 应答结果对象，包含查询结果集。
     */
    @OperationLog(type = SysOperationLogType.LIST)
    @GetMapping("/directoryList")
    public ResponseResult<MyPageData<DirectoryInfoVo>> directoryInfoList(Long parentId,Integer isHotspot,@RequestParam(required = false) Integer isAll) {
//        if (ObjectUtils.isEmpty(parentId)){
//            return ResponseResult.error("NO-ERROR","父级Id为空");
//        }
        MyPageData<DirectoryInfoVo> directoryInfoVoMyPageData = basicToWebServicel.getDirectoryInfoList(parentId, isHotspot, isAll);
        return ResponseResult.success(directoryInfoVoMyPageData);
    }

//    /**
//     * 列出符合过滤条件的公司信息管理列表。
//     *  @return 应答结果对象，包含查询结果集。
//     */
//    @GetMapping("/companyList")
//    public ResponseResult<MyPageData<CompanyInfoVo>> companyInfoList(@NotNull(message = "公司类型(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));
//    }



    /**
     * 生成随机的浏览量,点赞数和热度值。
     * @return 应答结果对象，包含查询结果集。
     */
    @OperationLog(type = SysOperationLogType.UPDATE)
    @GetMapping("/generate")
    public void generate(){
        basicToWebServicel.generate();
    }


    /**
     * 列出符合过滤条件的banner管理列表。
     * @return 应答结果对象，包含查询结果集。
     */
    @OperationLog(type = SysOperationLogType.LIST)
    @GetMapping("/businessBannerList")
    public ResponseResult<MyPageData<TourBusinessBannerVo>> getBusinessBannerList(@NotNull(message = "所属业务类型(businessType)不能为空") Long businessType) {
        List<TourBusinessBanner> tourBusinessBannerList = basicToWebServicel.getTourBusinessBannerList(businessType);
        return ResponseResult.success(MyPageUtil.makeResponseData(tourBusinessBannerList, TourBusinessBannerVo.class));
    }
}
