package com.psg.dlsysinfo.dl_sysinfo_server.controller;

import com.psg.dlsysinfo.dl_sysinfo_server.dto.DemoDeviceRequestDTO;
import com.psg.dlsysinfo.dl_sysinfo_server.service.DemoDeviceGeneratorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
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 com.psg.dlsysinfo.dl_sysinfo_server.entity.Devices;


@RestController
@RequestMapping("/api/system/devices/demo")
public class DemoController {

    @Autowired
    private DemoDeviceGeneratorService demoDeviceGeneratorService;

    @PostMapping
    public ResponseEntity<?> createDemoDevice(@RequestBody DemoDeviceRequestDTO request) {
        try {
            Devices demoDevice = demoDeviceGeneratorService.generateDemoDeviceForClient(request.getClientId());
            return ResponseEntity.ok(demoDevice);
        } catch (Exception e) {
            System.err.println("❌ Failed to generate demo device: " + e.getMessage());
            e.printStackTrace();
            return ResponseEntity.status(500).body("Failed to generate demo device");
        }
    }


}

