package com.sikey.wa04.api.location.client.rest;

import com.sikey.wa04.business.application.service.location.LocationService;
import com.sikey.wa04.business.infrastructure.configuration.ProjectContextConstant;
import com.sikey.wa04.business.infrastructure.dto.request.ask.LocationAskRequest;
import com.sikey.wa04.business.infrastructure.dto.request.iot.IotRequest;
import com.sikey.wa04.business.infrastructure.dto.request.trajectory.LocationTrajectoryRequest;
import com.sikey.wa04.business.infrastructure.dto.response.iot.IotResponse;
import com.sikey.wa04.business.infrastructure.dto.response.trajectory.LocationTrajectoryResponse;
import com.sikey.wa04.common.BaseController;
import com.sikey.wa04.common.dto.header.GenericManufacturerHeader;
import com.sikey.wa04.common.interceptor.Authenticated;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(ProjectContextConstant.LOCATION_URL + "/location")
public class LocationController extends BaseController {

    @Resource
    private LocationService locationService;

    /**
     * Ask for location
     *
     * @param request LocationAskRequest
     */
    @Authenticated
    @PostMapping("/ask")
    public void ask(@Valid @RequestBody LocationAskRequest request) {
        request.setHeader(genericManufacturerHeader());
        locationService.ask(request);
    }

    /**
     * Get trajectory
     *
     * @param request LocationTrajectoryRequest
     * @return LocationTrajectoryResponse
     */
    @Authenticated
    @GetMapping("/trajectory")
    public LocationTrajectoryResponse trajectory(@Valid LocationTrajectoryRequest request) {
        return locationService.trajectory(request);
    }

    /**
     * iot
     *
     * @param request
     * @param req
     * @return
     */
    @Authenticated
    @PostMapping("/iot")
    public IotResponse iot(@Valid @RequestBody IotRequest request, HttpServletRequest req) throws Exception {
        GenericManufacturerHeader genericManufacturerHeader = genericManufacturerHeader();
        return locationService.iot(request,req,genericManufacturerHeader);
    }

}
