using Cloud.Requests;
using Cloud.Services;
using Cloud.Services.Broker;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.ComponentModel.DataAnnotations;
using System.Text.Json;

namespace Cloud.Controllers
{
	[Authorize]
	[ApiController]
	[Route("api")]
	public class ValveController : ControllerBase
	{
		//Контроллер вентиля

		private readonly IBrokerService _kafkaService;

		public ValveController(IBrokerService kafkaService)
		{
			_kafkaService = kafkaService;
		}

		[HttpPost("farm/{farmId}/greenhouse/{ghId}/watering")]
		public async Task<IActionResult> interactValve([FromBody] ValveRequest request, int farmId, int ghId)
		{
			var kafkaRequest = new
			{
				FarmId = farmId,
				GreenHouseId = ghId,
				SomeAction = request.Action,
			};

			var message = JsonSerializer.Serialize(kafkaRequest);
			return Ok(kafkaRequest);
			
			/*await _kafkaService.ProduceAsync("ValvesHeatersRequest", message);

			return Ok($"Valve status is {request.Action}");*/
		}
	}
}