package com.sikey.wa04.api.user.client.wristwatch;

import com.sikey.wa04.business.application.service.user.DeviceService;
import com.sikey.wa04.business.infrastructure.configuration.ProjectContextConstant;
import com.sikey.wa04.business.infrastructure.dto.request.device.GetAppManageRequest;
import com.sikey.wa04.business.infrastructure.dto.request.device.DeviceWristwatchBindingRequest;
import com.sikey.wa04.business.infrastructure.dto.request.device.ExchangeDeviceRequest;
import com.sikey.wa04.business.infrastructure.dto.request.device.PowerOnOrShutdownRequest;
import com.sikey.wa04.business.infrastructure.dto.response.device.DeviceWristwatchBindingResponse;
import com.sikey.wa04.business.infrastructure.dto.response.device.ExchangeDeviceResponse;
import com.sikey.wa04.business.infrastructure.dto.response.device.GetAppManageResponse;
import com.sikey.wa04.common.BaseController;
import com.sikey.wa04.common.dto.header.GenericManufacturerHeader;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(ProjectContextConstant.USER_CONTEXT_URL + "/user/child/device/wristwatch")
public class DeviceWristwatchController extends BaseController {
    private final DeviceService deviceService;

    public DeviceWristwatchController(DeviceService deviceServiceImpl) {
        this.deviceService = deviceServiceImpl;
    }

    /**
     * 交换三码
     *
     * @return Response
     */
    @GetMapping("/exchange")
    public ExchangeDeviceResponse exchange(@Valid ExchangeDeviceRequest request) {
        GenericManufacturerHeader genericManufacturerHeader = genericManufacturerHeader();
        return deviceService.exchange(request, genericManufacturerHeader);
    }


    @GetMapping("/binding")
    public DeviceWristwatchBindingResponse wristwatchBinding(@Valid DeviceWristwatchBindingRequest request) {
        GenericManufacturerHeader genericManufacturerHeader = genericManufacturerHeader();
        return deviceService.wristwatchBinding(request, genericManufacturerHeader);
    }

    /**
     * 设备开关机
     *
     * @param powerOnOrShutdownRequest 设备开关机请求
     * @return
     */
    @PostMapping("/powerOnOrShutdown")
    public void powerOnOrShutdown(@Valid @RequestBody PowerOnOrShutdownRequest powerOnOrShutdownRequest) {
        GenericManufacturerHeader genericManufacturerHeader = genericManufacturerHeader();
        deviceService.powerOnOrShutdown(powerOnOrShutdownRequest,genericManufacturerHeader);
    }

    /**
     * 获取三方应用管理
     *
     * @param request 获取三方应用管理请求
     * @return
     */
    @PostMapping("/getAppManageList")
    public GetAppManageResponse getAppManageList(@Valid @RequestBody GetAppManageRequest request) {
        GenericManufacturerHeader genericManufacturerHeader = genericManufacturerHeader();
        return deviceService.getAppManageList(request,genericManufacturerHeader, true);
    }

}
