using Lada.Framework.DTO.SmartTable;
using Ladaer.BackEnd.Infrastructures.DTO.Items.Premises;
using Ladaer.BackEnd.Infrastructures.DTO.Models.Premises;
using Ladaer.BackEnd.Infrastructures.Services.Premises;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Ladaer.BackEnd.Controllers.Premises
{
    [Route("api/[controller]")]
    [ApiController]
    [Authorize]
    public class PremiseScoringController : ControllerBase
    {
        private readonly IPremiseScoringService _service;

        public PremiseScoringController(IPremiseScoringService service)
        {
            _service = service;
        }

        /// <summary>
        /// Tìm kiếm tiêu chí chấm điểm
        /// </summary>
        [HttpPost("SearchCriteria")]
        [Authorize(Roles = "PremiseScoring.SearchCriteria")]
        public async Task<IActionResult> SearchCriteria([FromBody] SmartTableParam param)
        {
            var result = await _service.SearchCriteria(param);
            return Ok(result);
        }

        /// <summary>
        /// Lấy tiêu chí theo ID
        /// </summary>
        [HttpGet("GetCriteriaById/{id}")]
        [Authorize(Roles = "PremiseScoring.GetCriteriaById")]
        public async Task<IActionResult> GetCriteriaById(int id)
        {
            var result = await _service.GetCriteriaById(id);
            return Ok(result);
        }

        /// <summary>
        /// Tạo mới hoặc cập nhật tiêu chí (kèm options)
        /// </summary>
        [HttpPost("CreateOrUpdateCriteria")]
        [Authorize(Roles = "PremiseScoring.CreateOrUpdateCriteria")]
        public async Task<IActionResult> CreateOrUpdateCriteria([FromBody] PremiseScoringCriteriaModel model)
        {
            var result = await _service.CreateOrUpdateCriteria(model);
            return Ok(result);
        }

        /// <summary>
        /// Xóa tiêu chí (soft delete kèm options)
        /// </summary>
        [HttpDelete("DeleteCriteria/{id}")]
        [Authorize(Roles = "PremiseScoring.DeleteCriteria")]
        public async Task<IActionResult> DeleteCriteria(int id)
        {
            var result = await _service.DeleteCriteria(id);
            return Ok(result);
        }

        /// <summary>
        /// Lấy tất cả tiêu chí đang active (cho NV khi chấm điểm)
        /// </summary>
        [HttpGet("GetAllActiveCriteria")]
        [Authorize(Roles = "PremiseScoring.GetAllActiveCriteria")]
        public async Task<IActionResult> GetAllActiveCriteria()
        {
            var result = await _service.GetAllActiveCriteria();
            return Ok(result);
        }
    }
}
