using IdokladSdk.Models.Contact;
using Microsoft.AspNetCore.Mvc;
using Idoklad.Services;
namespace Idoklad.Controllers;
///
/// Contacts (customers/suppliers) agenda.
///
/// All endpoints require iDoklad credentials. Provide them as request headers
/// (X-ClientId, X-ClientSecret, X-ApplicationId) or rely on the service
/// environment defaults. See the Swagger description for details.
///
[ApiController]
[Route("contacts")]
[Produces("application/json")]
[Tags("Contacts")]
public sealed class ContactsController : ControllerBase
{
private readonly ContactsService _service;
public ContactsController(ContactsService service) => _service = service;
/// List contacts (paged).
[HttpGet]
public async Task List([FromQuery] int page = 1, [FromQuery] int pageSize = 20, CancellationToken ct = default)
=> Ok(await _service.ListAsync(page, pageSize, ct));
/// Get a contact detail by id.
[HttpGet("{id:int}")]
public async Task Detail(int id, CancellationToken ct)
=> Ok(await _service.DetailAsync(id, ct));
/// Get a pre-filled default contact model for creating a new contact.
[HttpGet("default")]
public async Task Default(CancellationToken ct)
=> Ok(await _service.DefaultAsync(ct));
/// Create a new contact.
[HttpPost]
public async Task Create([FromBody] ContactPostModel model, CancellationToken ct)
=> Ok(await _service.CreateAsync(model, ct));
/// Update an existing contact (the model id identifies the contact).
[HttpPatch]
public async Task Update([FromBody] ContactPatchModel model, CancellationToken ct)
=> Ok(await _service.UpdateAsync(model, ct));
/// Delete a contact by id.
[HttpDelete("{id:int}")]
public async Task Delete(int id, CancellationToken ct)
=> Ok(await _service.DeleteAsync(id, ct));
}