package kr.gmtc.gw.dev.restdev.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import kr.gmtc.gw.dev.restdev.vo.AImetaTestVO;
import kr.gmtc.gw.dev.restdev.vo.AImetaTestVO.Data;
import kr.gmtc.gw.dev.restdev.vo.AImetaTestVO.Header;

@RestController
public class RestReqeustController {
    

    @RequestMapping(value={"getTest/{param1}/{param2}"}, method=RequestMethod.GET)
    public String getTest(@PathVariable String param1, @PathVariable String param2){
        String sParam1, sParam2;

        sParam1 = param1;
        sParam2 = param2;


        return "return :" + sParam1 + "/" + sParam2;

    }

    @RequestMapping(value={"getVideoTest"}, method=RequestMethod.GET)
    public AImetaTestVO getMessage() {
        // JSON 형식의 메시지를 생성
        Header header = new Header("200", "OK");

        List<Data> dataList = new ArrayList<>();
        Random random = new Random();

        for (int i = 0; i < 2; i++) { // 두 개의 데이터 생성
            String on_arcrft = random.nextBoolean() ? "true" : "false";
            String stts_cls = getRandomStatusClass(random);
            String arcrft_tp = "A380-800";
            String zn_id = String.valueOf(106 + i);
            List<String> bb_tlp = Arrays.asList("241", "489");
            List<String> crd_frm = Arrays.asList("286", "500");
            List<String> cc_id = Arrays.asList(String.valueOf(random.nextInt(4) + 102), String.valueOf(random.nextInt(4) + 102)); // 102부터 105까지의 랜덤값
            List<String> crd_glb = Arrays.asList("37.344556", "127.422913");
            List<String> bb_brp = Arrays.asList("331", "512");
            String dtct_tm = "";
            String arln = "KOR-001";
            String trck_id = "";

            Data data = new Data();
            data.setOn_arcrft(on_arcrft);
            data.setStts_cls(stts_cls);
            data.setArcrft_tp(arcrft_tp);
            data.setZn_id(zn_id);
            data.setBb_brp(bb_brp);
            data.setBb_tlp(bb_tlp);
            data.setCrd_frm(crd_frm);
            data.setCc_id(cc_id);
            data.setCrd_glb(crd_glb);
            data.setDtct_tm(dtct_tm);
            data.setArln(arln);
            data.setTrck_id(trck_id);

            dataList.add(data);
        }

        return new AImetaTestVO(header, dataList);
    }

    private String getRandomStatusClass(Random random) {
        String[] statusClasses = {"brdg_cnnctd", "crg_dr_opnd", "twng_cr_cnnctd"};
        int randomIndex = random.nextInt(statusClasses.length);
        return statusClasses[randomIndex];
    }



}
