using Api.Services.Interfaces;
using Common.Dtos.Subject;
using Microsoft.AspNetCore.Mvc;

namespace Api.Controllers
{
    [ApiController]
    public class SubjectController(ISubjectService service) : ControllerBase
    {
        private readonly ISubjectService _service = service;

        [HttpPost]
        [Route("admin/subject/create")]
        public async Task<ActionResult> CreateAsync([FromBody] CreateSubjectRequest request)
        {
            var result = await _service.CreateAsync(request);
            return result.Ok ? Ok(result.CreateSubjectResult) : Conflict(result.Error);
        }

        [HttpGet]
        [Route("admin/subject")]
        public async Task<ActionResult> GetAllAsync()
        {
            var result = await _service.GetAllAsync();
            return result.Length != 0 ? Ok(result) : NoContent();
        }

        [HttpGet]
        [Route("admin/subject/paged")]
        public async Task<ActionResult> GetAllPagedAsync([FromQuery] GetSubjectsRequest request)
        {
            var result = await _service.GetAllPagedAsync(request);
            return Ok(result);
        }
    }
}
