package com.xiang.xservice.application.script.fwd.server;

import com.xiang.xservice.application.script.fwd.mapper.FwdUserConfigMapper;
import com.xiang.xservice.basic.common.req.BaseRequest;
import com.xiang.xservice.basic.common.resp.Result;
import com.xiang.xservice.application.script.fwd.entity.resp.http.perform.Perform;
import com.xiang.xservice.application.script.fwd.entity.resp.http.perform.ProjectsResp;
import com.xiang.xservice.application.script.fwd.entity.resp.http.perform.SeatPlanStatus;
import com.xiang.xservice.application.script.fwd.service.IPerformService;
import com.xiang.xservice.application.script.fwd.service.IPerformServiceHttp;
import lombok.RequiredArgsConstructor;
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.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: xiang
 * @Date: 2025-07-24 16:55
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/system/fwd/outer")
public class FwdOuterController {

    private final IPerformServiceHttp performServiceHttp;
    private final IPerformService performService;
    private final FwdUserConfigMapper fwdUserConfigMapper;
    private static final List<Long> FREQUENT_IDS = List.of(50438548L, 35320661L, 50436621L, 50442739L);


    @GetMapping("/getShowProjects")
    public Result<ProjectsResp> getShowProjects() {
        ProjectsResp showProjectsFromHttp = performServiceHttp.getShowProjectsFromHttp(new BaseRequest());
        return Result.success("查询成功!", showProjectsFromHttp);
    }

    @GetMapping("/getProjectInfo/{id}")
    public Result<Perform> getProjectInfo(@PathVariable("id") Long id) {
        String token = fwdUserConfigMapper.getAvailableUser().get(0).getToken();
        Perform performsByProjectIdFromHttp = performServiceHttp.getPerformsByProjectIdFromHttp(id, token);
        return Result.success("查询成功!", performsByProjectIdFromHttp);
    }

    @GetMapping("/getPerformsByProjectIdFromHttp/{id}")
    public Result<Perform> getPerformsByProjectIdFromHttp(@PathVariable("id") Long id) {
        String token = fwdUserConfigMapper.getAvailableUser().get(0).getToken();
        Perform performsByProjectIdFromHttp = performServiceHttp.getPerformsByProjectIdFromHttp(id, token);
        return Result.success("查询成功!", performsByProjectIdFromHttp);
    }

    @PostMapping("/createOrder")
    public Result<String> createOrder(Long projectId) throws Exception {
        String token = fwdUserConfigMapper.getAvailableUser().get(0).getToken();
        if (performService.createProjectOrder(projectId, FREQUENT_IDS, token)) {
            return Result.success("下单成功!");
        }
        return Result.error("下单失败!");
    }

    @GetMapping("/getSeatPlanStatus")
    public Result<SeatPlanStatus> getSeatPlanStatu (@RequestParam List<Long> ids) {
        String token = fwdUserConfigMapper.getAvailableUser().get(0).getToken();
        List<SeatPlanStatus> seatPlanStatusFromHttp = performServiceHttp.getSeatPlanStatusFromHttp(ids, token);
        return Result.success("查询成功!", seatPlanStatusFromHttp);
    }

}
