using Lada.Framework.DTO;
using Lada.Framework.Infrastructures.Helpers;
using ladaexpress.vn.Infrastructures.DTO.Models.Hr;
using ladaexpress.vn.Infrastructures.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using System.Linq;

namespace ladaexpress.vn.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class CandidateController : ControllerBase
    {
        private readonly ICandidateService _candidateService;

        public CandidateController(ICandidateService candidateService)
        {
            _candidateService = candidateService;
        }


        [HttpPost("Apply")]
        public async Task<IActionResult> Apply([FromForm] ApplyModel applyModel)
        {
            var result = new BaseResult();
            if (!ModelState.IsValid)
            {
                //IEnumerable<ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors);
                var allErrors = ModelState.Values.SelectMany(v => v.Errors.Select(b => b.ErrorMessage)).ToList();
                result.Result = Result.Failed;
                result.Message = string.Join("\n", allErrors);
                return Ok(result);
            }
            result = await _candidateService.Apply(applyModel);
            return Ok(result);
        }

        [HttpGet("Test")]
        public async Task<IActionResult> Test()
        {

            return Ok("Test");
        }
    }
}
