package com.ycwl.basic.controller.mobile;

import com.github.pagehelper.PageInfo;
import com.ycwl.basic.annotation.IgnoreToken;
import com.ycwl.basic.constant.BaseContextHandler;
import com.ycwl.basic.model.mobile.scenic.ScenicAppVO;
import com.ycwl.basic.model.mobile.scenic.ScenicDeviceCountVO;
import com.ycwl.basic.model.mobile.scenic.ScenicIndexVO;
import com.ycwl.basic.model.mobile.scenic.content.ContentPageVO;
import com.ycwl.basic.model.pc.scenic.entity.ScenicConfigEntity;
import com.ycwl.basic.model.pc.scenic.entity.ScenicEntity;
import com.ycwl.basic.model.pc.scenic.req.ScenicReqQuery;
import com.ycwl.basic.model.pc.scenic.resp.ScenicConfigResp;
import com.ycwl.basic.model.pc.scenic.resp.ScenicRespVO;
import com.ycwl.basic.repository.ScenicRepository;
import com.ycwl.basic.service.mobile.AppScenicService;
import com.ycwl.basic.service.pc.FaceService;
import com.ycwl.basic.utils.ApiResponse;
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.PathVariable;
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.ArrayList;
import java.util.List;

/**
 * @Author：longbinbin
 * @Date：2024/12/5 10:22
 */
@Slf4j
@RestController
@RequestMapping("/api/mobile/scenic/v1")
// 景区相关接口
public class AppScenicController {

    @Autowired
    private FaceService faceService;
    @Autowired
    private AppScenicService appScenicService;
    @Autowired
    private ScenicRepository scenicRepository;
    private static final List<String> ENABLED_USER_IDs = new ArrayList<>(){{
        add("3932535453961555968");
        add("3936121342868459520");
        add("3936940597855784960");
    }};

    // 分页查询景区列表
    @PostMapping("/page")
    public ApiResponse<PageInfo<ScenicEntity>> pageQuery(@RequestBody ScenicReqQuery scenicReqQuery){
        String userId = BaseContextHandler.getUserId();
        if (ENABLED_USER_IDs.contains(userId)) {
            return appScenicService.pageQuery(scenicReqQuery);
        } else {
            return ApiResponse.success(new PageInfo<>(new ArrayList<>()));
        }
    }
    // 根据id查询景区详情
    @IgnoreToken
    @GetMapping("/{id}")
    public ApiResponse<ScenicRespVO> getDetails(@PathVariable Long id){
        return appScenicService.getDetails(id);
    }

    @GetMapping("/{id}/config")
    @IgnoreToken
    public ApiResponse<ScenicConfigResp> getConfig(@PathVariable Long id){
        ScenicConfigEntity scenicConfig = scenicRepository.getScenicConfig(id);
        ScenicConfigResp resp = new ScenicConfigResp();
        resp.setBookRoutine(scenicConfig.getBookRoutine());
        resp.setForceFinishTime(scenicConfig.getForceFinishTime());
        resp.setTourTime(scenicConfig.getTourTime());
        resp.setSampleStoreDay(scenicConfig.getSampleStoreDay());
        resp.setFaceStoreDay(scenicConfig.getFaceStoreDay());
        resp.setVideoStoreDay(scenicConfig.getVideoStoreDay());
        resp.setAllFree(scenicConfig.getAllFree());
        resp.setDisableSourceVideo(scenicConfig.getDisableSourceVideo());
        resp.setDisableSourceImage(scenicConfig.getDisableSourceImage());
        resp.setAntiScreenRecordType(scenicConfig.getAntiScreenRecordType());
        resp.setVideoSourceStoreDay(scenicConfig.getVideoSourceStoreDay());
        resp.setImageSourceStoreDay(scenicConfig.getImageSourceStoreDay());
        resp.setUserSourceExpireDay(scenicConfig.getUserSourceExpireDay());
        resp.setBrokerDirectRate(scenicConfig.getBrokerDirectRate());
        resp.setVideoSourcePackHint(scenicConfig.getVideoSourcePackHint());
        resp.setImageSourcePackHint(scenicConfig.getImageSourcePackHint());
        resp.setVoucherEnable(scenicConfig.getVoucherEnable());
        return ApiResponse.success(resp);
    }

    // 查询景区设备总数和拍到用户的机位数量
    @GetMapping("/{scenicId}/deviceCount/")
    public ApiResponse<ScenicDeviceCountVO> deviceCountByScenicId(@PathVariable Long scenicId){
        return appScenicService.deviceCountByScenicId(scenicId);
    }

    // 景区视频源素材列表
    @GetMapping("/contentList/")
    public ApiResponse<List<ContentPageVO>> contentList() {
        return faceService.contentListUseDefaultFace();
    }

    // 景区视频源素材列表
    @GetMapping("/face/{faceId}/contentList")
    public ApiResponse<List<ContentPageVO>> contentList(@PathVariable Long faceId) {
        List<ContentPageVO> contentPageVOS = faceService.faceContentList(faceId);
        return  ApiResponse.success(contentPageVOS);
    }

    @PostMapping("/nearby")
    public ApiResponse<List<ScenicAppVO>> nearby(@RequestBody ScenicIndexVO scenicIndexVO) {
        List<ScenicAppVO> list = appScenicService.scenicListByLnLa(scenicIndexVO);
        return ApiResponse.success(list);
    }
}
