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

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore;
import com.github.pagehelper.page.PageMethod;
import com.tourism.common.core.annotation.MyRequestBody;
import com.tourism.common.core.constant.ErrorCodeEnum;
import com.tourism.common.core.object.*;
import com.tourism.common.core.upload.UpDownloaderFactory;
import com.tourism.common.core.util.MyModelUtil;
import com.tourism.common.core.util.MyPageUtil;
import com.tourism.common.redis.cache.SessionCacheHelper;
import com.tourism.webadmin.back.dto.TourismProjectDto;
import com.tourism.webadmin.back.model.TourismProject;
import com.tourism.webadmin.back.service.TourismProjectService;
import com.tourism.webadmin.back.vo.TourismProjectVo;
import com.tourism.webadmin.config.ApplicationConfig;
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;

/**
 * 旅游项目管理操作控制器类。
 *
 * @author 吃饭睡觉
 * @date 2024-09-06
 */
@Tag(name = "网页旅游项目管理接口")
@Slf4j
@RestController
@SaIgnore
@RequestMapping("/website/tourism/project")
public class TourismProjectToWebController {

    @Autowired
    private TourismProjectService tourismProjectService;

    /**
     * 列出符合过滤条件的旅游项目管理列表。
     *
     * @param tourismProjectDtoFilter 过滤对象。
     * @param orderParam 排序参数。
     * @param pageParam 分页参数。
     * @return 应答结果对象，包含查询结果集。
     */
    @PostMapping("/list")
    public ResponseResult<MyPageData<TourismProjectVo>> list(
            @MyRequestBody TourismProjectDto tourismProjectDtoFilter,
            @MyRequestBody MyOrderParam orderParam,
            @MyRequestBody MyPageParam pageParam) {
        if (pageParam != null) {
            PageMethod.startPage(pageParam.getPageNum(), pageParam.getPageSize(), pageParam.getCount());
        }
        TourismProject tourismProjectFilter = MyModelUtil.copyTo(tourismProjectDtoFilter, TourismProject.class);
        String orderBy = MyOrderParam.buildOrderBy(orderParam, TourismProject.class);
        List<TourismProject> tourismProjectList =
                tourismProjectService.getTourismProjectListWithRelation(tourismProjectFilter, orderBy);
        return ResponseResult.success(MyPageUtil.makeResponseData(tourismProjectList, TourismProjectVo.class));
    }

    /**
     * 查看指定旅游项目管理对象详情。
     *
     * @param id 指定对象主键Id。
     * @return 应答结果对象，包含对象详情。
     */
//    @SaCheckPermission("tourismProject.view")
    @GetMapping("/detail")
    public ResponseResult<TourismProjectVo> detail(@RequestParam Long id) {
        TourismProject tourismProject = tourismProjectService.getByIdWithRelation(id, MyRelationParam.full());
        if (tourismProject == null) {
            return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST);
        }
        TourismProjectVo tourismProjectVo = MyModelUtil.copyTo(tourismProject, TourismProjectVo.class);
        return ResponseResult.success(tourismProjectVo);
    }
}
