using MyNewProjectName.Application.Features.Sample.Commands.CreateSample;
using MyNewProjectName.Application.Features.Sample.Queries.GetSamples;
using MyNewProjectName.Contracts.DTOs.Requests;
using MyNewProjectName.Contracts.DTOs.Responses;
using Microsoft.AspNetCore.Mvc;

namespace MyNewProjectName.WebAPI.Controllers;

/// <summary>
/// Sample controller to demonstrate CQRS pattern
/// </summary>
public class SamplesController : BaseApiController
{
    /// <summary>
    /// Get all samples
    /// </summary>
    [HttpGet]
    [ProducesResponseType(typeof(ApiResponse<List<SampleResponse>>), StatusCodes.Status200OK)]
    public async Task<IActionResult> GetAll()
    {
        var result = await Mediator.Send(new GetSamplesQuery());
        return Ok(ApiResponse<List<SampleDto>>.SuccessResponse(result));
    }

    /// <summary>
    /// Create a new sample
    /// </summary>
    [HttpPost]
    [ProducesResponseType(typeof(ApiResponse<Guid>), StatusCodes.Status201Created)]
    [ProducesResponseType(typeof(ApiResponse), StatusCodes.Status400BadRequest)]
    public async Task<IActionResult> Create([FromBody] CreateSampleRequest request)
    {
        var command = new CreateSampleCommand(request.Name, request.Description);
        var id = await Mediator.Send(command);
        return CreatedAtAction(nameof(GetAll), new { id }, ApiResponse<Guid>.SuccessResponse(id, "Sample created successfully"));
    }
}
