using Microsoft.AspNetCore.Mvc;
using System.Linq;
using System.Threading.Tasks;
using XYY.Model.Standard.Finance;
using XYY.Core.Standard.Mvc;
using XYY.Data.Standard.Finance;
using XYY.Service.Standard.Finance;

namespace XYY.Api.Finance.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class FinanceIncidentalTypeController : ApiControllerBase
    {
        private IFinanceIncidentalTypeRepository _financeIncidentalTypeRepository;
        private ILadingBillService _ladingBillService;

        public FinanceIncidentalTypeController(IFinanceIncidentalTypeRepository financeIncidentalTypeRepository, ILadingBillService ladingBillService)
        {
            _financeIncidentalTypeRepository = financeIncidentalTypeRepository;
            _ladingBillService = ladingBillService;
        }

        public async Task<IActionResult> QueryAll()
        {
            var data = await _financeIncidentalTypeRepository.QueryAsync();
            return Ok(data);
        }

        public async Task<IActionResult> GetFinanceIncidentalTypes()
        {
            var data = (await _financeIncidentalTypeRepository.QueryAsync()).ToList();
            return Ok(data);
        } 

        public async Task<IActionResult> Add(Finance_IncidentalType finance_IncidentalType)
        {
            await _ladingBillService.RefreshIncidentalTypesCache();
            await _financeIncidentalTypeRepository.InsertAsync(finance_IncidentalType);
            return Ok();
        }

        public async Task<IActionResult> Edit(Finance_IncidentalType finance_IncidentalType)
        {
            await _ladingBillService.RefreshIncidentalTypesCache();
            await _financeIncidentalTypeRepository.UpdateAsync(finance_IncidentalType);
            return Ok();
        }
    }
}
