package com.alterdekim.game.controller;

import com.alterdekim.flash.decompiler.compiler.FlashCompiler;
import com.alterdekim.flash.decompiler.mapper.FlashMapper;
import com.alterdekim.flash.decompiler.translator.Java2Flash;
import com.alterdekim.game.service.MRService;
import com.alterdekim.game.service.MRTService;
import com.alterdekim.game.service.ROService;
import com.alterdekim.game.service.TRService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;

@Slf4j
@RestController
public class CacheController {

    @Autowired
    private MRService mrService;

    @Autowired
    private MRTService mrtService;

    @Autowired
    private ROService roService;

    @Autowired
    private TRService trService;

    @GetMapping("/cache/resources.swf")
    public ResponseEntity<byte[]> generateResources() {
        try {
            byte[] b = Files.readAllBytes(Path.of("cache/resources.swf"));
            return ResponseEntity.ok()
                    .contentType(MediaType.parseMediaType("application/x-shockwave-flash"))
                    .contentLength(b.length)
                    .body(b);
        } catch (IOException e) {
            log.error("generateResources error: {}", e.getMessage());
        }
        return ResponseEntity.noContent().build();
    }
}