using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using XPrintServer.Business.Services;
using XPrintServer.DataModel.Models;

namespace XPrintServer.Api.Controllers.Common
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ModelPartController : ControllerBase
    {

        private readonly IHttpContextAccessor _httpContextAccessor;
        private readonly ModelPartService _modelPartService;
        private readonly ActionLogService _actionLogService;

        public ModelPartController(IHttpContextAccessor httpContextAccessor, ModelPartService modelPartService, ActionLogService actionLogService)
        {
            _httpContextAccessor = httpContextAccessor;
            _modelPartService = modelPartService;
            _actionLogService = actionLogService;
        }

        //[HttpPost]
        //public async Task<ActionResult> AddOrUpdateModelParts([FromBody] List<ModelPart> modelParts)
        //{
        //    try
        //    {
        //        await _modelPartService.AddOrUpdateModelParts(modelParts);
        //        return Ok(true);
        //    }
        //    catch (Exception ex)
        //    {
        //        await _actionLogService.AddActionLog(new ActionLog { Title = "AddOrUpdateModelParts Error", Content = ex.Message + " " + ex.StackTrace, DateTime = DateTime.Now });
        //        return StatusCode(500, ex.Message);
        //    }
        //}


        [HttpPost]
        public async Task<ActionResult> ModePartsFormModelId([FromBody] Guid Id)
        {
            try
            {
                var modelPartList = await _modelPartService.GetModePartsFormModelId(Id);
                return Ok(modelPartList);
            }
            catch (Exception ex)
            {
                await _actionLogService.AddActionLog(new ActionLog { Title = "ModePartsFormModelId Error", Content = ex.Message + " " + ex.StackTrace, DateTime = DateTime.Now });
                return StatusCode(500, ex.Message);
            }
        }
    }
}
