using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SolutionErp.Application.Office;

namespace SolutionErp.Api.Controllers;

// Phase 10.2 G-O1 (S34) — Danh bạ nội bộ.
// 1 endpoint readonly. Class-level [Authorize] — mọi authenticated user thấy được
// (không restrict admin-only vì danh bạ nội bộ default open cho NV tra cứu nhau).
[ApiController]
[Route("api/directory")]
[Authorize]
public class DirectoryController(IMediator mediator) : ControllerBase
{
    [HttpGet]
    public async Task<ActionResult<List<DirectoryItemDto>>> Get(
        [FromQuery] string? search = null,
        [FromQuery] Guid? departmentId = null,
        CancellationToken ct = default)
        => Ok(await mediator.Send(new GetDirectoryQuery(search, departmentId), ct));
}
