using Marco.Pms.DataAccess.Data;
using Marco.Pms.Model.Dtos.Activities;
using Marco.Pms.Model.Dtos.Collection;
using Marco.Pms.Model.Dtos.DocumentManager;
using Marco.Pms.Model.Dtos.Expenses.Masters;
using Marco.Pms.Model.Dtos.Master;
using Marco.Pms.Model.Forum;
using Marco.Pms.Model.Mapper;
using Marco.Pms.Model.Master;
using Marco.Pms.Model.Utilities;
using Marco.Pms.Model.ViewModels.Forum;
using Marco.Pms.Model.ViewModels.Master;
using Marco.Pms.Services.Service.ServiceInterfaces;
using MarcoBMS.Services.Helpers;
using MarcoBMS.Services.Service;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;

namespace Marco.Pms.Services.Controllers
{
    [Authorize]
    [Route("api/[controller]")]
    [ApiController]
    public class MasterController : ControllerBase
    {
        private readonly ApplicationDbContext _context;
        private readonly UserHelper _userHelper;
        private readonly ILoggingService _logger;
        private readonly IMasterService _masterService;
        private readonly Guid tenantId;
        public MasterController(ApplicationDbContext context, UserHelper userHelper, ILoggingService logger, IMasterService masterService)
        {
            _context = context;
            _userHelper = userHelper;
            _logger = logger;
            _masterService = masterService;
            tenantId = userHelper.GetTenantId();
        }

        #region =================================================================== Recurring Payment Status APIs ===================================================================

        [HttpGet("recurring-status/list")]
        public async Task<IActionResult> GetRecurringPaymentStatus()
        {
            var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.GetRecurringPaymentStatusAsync(loggedInEmployee, tenantId);
            return StatusCode(response.StatusCode, response);
        }

        #endregion

        #region =================================================================== Currency APIs ===================================================================

        [HttpGet("currencies/list")]
        public async Task<IActionResult> GetCurrency()
        {
            var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.GetCurrencyAsync(loggedInEmployee, tenantId);
            return StatusCode(response.StatusCode, response);
        }

        #endregion

        #region =================================================================== Organization Type APIs ===================================================================

        [HttpGet("organization-type/list")]
        public async Task<IActionResult> GetOrganizationTypes()
        {
            var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.GetOrganizationTypesAsync(loggedInEmployee, tenantId);
            return StatusCode(response.StatusCode, response);
        }

        #endregion

        #region =================================================================== Global Services APIs ===================================================================

        [HttpGet("global-service/list")]
        public async Task<IActionResult> GetGlobalServices()
        {
            var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.GetGlobalServicesAsync(loggedInEmployee, tenantId);
            return StatusCode(response.StatusCode, response);
        }

        [HttpPost("global-service/create")]
        public async Task<IActionResult> CreateGlobalService([FromBody] ServiceMasterDto serviceMasterDto)
        {
            var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.CreateGlobalServiceAsync(serviceMasterDto, loggedInEmployee, tenantId);
            return StatusCode(response.StatusCode, response);
        }

        [HttpPut("global-service/edit/{id}")]
        public async Task<IActionResult> UpdateGlobalService(Guid id, [FromBody] ServiceMasterDto serviceMasterDto)
        {
            var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.UpdateServiceAsync(id, serviceMasterDto, loggedInEmployee, tenantId);
            return StatusCode(response.StatusCode, response);
        }

        [HttpDelete("global-service/delete/{id}")]
        public async Task<IActionResult> DeleteGlobalService(Guid id, [FromQuery] bool active = false)
        {
            var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.DeleteServiceAsync(id, active, loggedInEmployee, tenantId);
            return StatusCode(response.StatusCode, response);
        }

        #endregion

        #region =================================================================== Services APIs ===================================================================

        [HttpGet("service/list")]
        public async Task<IActionResult> GetServices()
        {
            var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.GetServicesAsync(loggedInEmployee, tenantId);
            return StatusCode(response.StatusCode, response);
        }

        [HttpGet("service/all/list")]
        public async Task<IActionResult> GetServiceDetailsList([FromQuery] Guid? serviceId)
        {
            var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.GetServiceDetailsListAsync(serviceId, loggedInEmployee, tenantId);
            return StatusCode(response.StatusCode, response);
        }

        [HttpPost("service/create")]
        public async Task<IActionResult> CreateService([FromBody] ServiceMasterDto serviceMasterDto)
        {
            var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.CreateServiceAsync(serviceMasterDto, loggedInEmployee, tenantId);
            return StatusCode(response.StatusCode, response);
        }

        [HttpPut("service/edit/{id}")]
        public async Task<IActionResult> UpdateService(Guid id, [FromBody] ServiceMasterDto serviceMasterDto)
        {
            var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.UpdateServiceAsync(id, serviceMasterDto, loggedInEmployee, tenantId);
            return StatusCode(response.StatusCode, response);
        }

        [HttpDelete("service/delete/{id}")]
        public async Task<IActionResult> DeleteService(Guid id, [FromQuery] bool active = false)
        {
            var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.DeleteServiceAsync(id, active, loggedInEmployee, tenantId);
            return StatusCode(response.StatusCode, response);
        }

        #endregion

        #region =================================================================== Activity Group APIs ===================================================================

        [HttpGet("activity-group/list")]
        public async Task<IActionResult> GetActivityGroups([FromQuery] Guid? serviceId)
        {
            var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.GetActivityGroupsAsync(serviceId, loggedInEmployee, tenantId);
            return StatusCode(response.StatusCode, response);
        }

        [HttpPost("activity-group/create")]
        public async Task<IActionResult> CreateActivityGroup([FromBody] ActivityGroupDto activityGroupDto)
        {
            var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.CreateActivityGroupAsync(activityGroupDto, loggedInEmployee, tenantId);
            return StatusCode(response.StatusCode, response);
        }

        [HttpPut("activity-group/edit/{id}")]
        public async Task<IActionResult> UpdateActivityGroup(Guid id, [FromBody] ActivityGroupDto activityGroupDto)
        {
            var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.UpdateActivityGroupAsync(id, activityGroupDto, loggedInEmployee, tenantId);
            return StatusCode(response.StatusCode, response);

        }

        [HttpDelete("activity-group/delete/{id}")]
        public async Task<IActionResult> DeleteActivityGroup(Guid id, [FromQuery] bool active = false)
        {
            var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.DeleteActivityGroupAsync(id, active, loggedInEmployee, tenantId);
            return StatusCode(response.StatusCode, response);
        }
        #endregion

        #region =================================================================== Activity APIs ===================================================================

        [HttpGet]
        [Route("activities")]
        public async Task<IActionResult> GetActivitiesMaster([FromQuery] Guid? activityGroupId)
        {
            var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.GetActivitiesMasterAsync(activityGroupId, loggedInEmployee, tenantId);
            return StatusCode(response.StatusCode, response);
        }

        [HttpPost("activity")]
        public async Task<IActionResult> CreateActivity([FromBody] CreateActivityMasterDto createActivity)
        {
            var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.CreateActivityAsync(createActivity, loggedInEmployee, tenantId);
            return StatusCode(response.StatusCode, response);
        }

        [HttpPost("activity/edit/{id}")]
        public async Task<IActionResult> UpdateActivity(Guid id, [FromBody] CreateActivityMasterDto createActivity)
        {
            var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.UpdateActivityAsync(id, createActivity, loggedInEmployee, tenantId);
            return StatusCode(response.StatusCode, response);
        }

        [HttpDelete("activity/delete/{id}")]
        public async Task<IActionResult> DeleteActivity(Guid id, [FromQuery] bool active = false)
        {
            var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.DeleteActivityAsync(id, active, loggedInEmployee, tenantId);
            return StatusCode(response.StatusCode, response);
        }

        #endregion

        #region =================================================================== Industry APIs ===================================================================

        [HttpGet]
        [Route("industries")]
        public async Task<IActionResult> GetIndustries()
        {
            Guid tenantId = _userHelper.GetTenantId();
            var industries = await _context.Industries.ToListAsync();

            _logger.LogInfo("{count} industry records fetched successfully from tenant {tenantId}", industries.Count, tenantId);
            return Ok(ApiResponse<object>.SuccessResponse(industries, System.String.Format("{0} industry records fetched successfully", industries.Count), 200));
        }

        #endregion

        #region =================================================================== Ticket Status APIs ===================================================================

        [HttpGet("ticket-status")]
        public async Task<IActionResult> GetTicketStatusMaster()
        {
            Guid tenantId = _userHelper.GetTenantId();
            List<TicketStatusVM> statusVMs = new List<TicketStatusVM>();
            List<TicketStatusMaster> statusMasters = await _context.TicketStatusMasters.Where(s => s.TenantId == tenantId).ToListAsync();
            foreach (var statusMaster in statusMasters)
            {
                statusVMs.Add(statusMaster.ToTicketStatusVMFromTicketStatusMaster());
            }

            _logger.LogInfo("{count} Ticket Status records fetched successfully from tenant {tenantId}", statusVMs.Count, tenantId);
            return Ok(ApiResponse<object>.SuccessResponse(statusVMs, System.String.Format("{0} Ticket Status records fetched successfully", statusVMs.Count), 200));
        }

        [HttpPost("ticket-status")]
        public async Task<IActionResult> CreateTicketStatusMaster([FromBody] TicketStatusMasterDto statusMasterDto)
        {
            Guid tenantId = _userHelper.GetTenantId();
            if (statusMasterDto != null)
            {
                TicketStatusMaster? statusMaster = statusMasterDto.ToTicketStatusMasterFromTicketStatusMasterDto(tenantId);
                _context.TicketStatusMasters.Add(statusMaster);
                await _context.SaveChangesAsync();

                TicketStatusVM statusVM = statusMaster.ToTicketStatusVMFromTicketStatusMaster();
                _logger.LogInfo("Ticket Status master {TicketStatusId} added successfully from tenant {tenantId}", statusMaster.Id, tenantId);
                return Ok(ApiResponse<object>.SuccessResponse(statusVM, "Ticket Status master added successfully", 200));
            }
            _logger.LogWarning("User sent empyt payload");
            return BadRequest(ApiResponse<object>.ErrorResponse("Sent Empty payload", "Sent Empty payload", 400));
        }

        [HttpPost("ticket-status/edit/{id}")]
        public async Task<IActionResult> UpdateTicketStatusMaster(Guid id, [FromBody] TicketStatusMasterDto statusMasterDto)
        {
            Guid tenantId = _userHelper.GetTenantId();
            if (statusMasterDto != null && statusMasterDto.Id != id)
            {
                TicketStatusMaster? statusMaster = await _context.TicketStatusMasters.AsNoTracking().FirstOrDefaultAsync(s => s.TenantId == tenantId && s.Id == statusMasterDto.Id);
                if (statusMaster != null)
                {
                    statusMaster = statusMasterDto.ToTicketStatusMasterFromTicketStatusMasterDto(tenantId);
                    _context.TicketStatusMasters.Update(statusMaster);
                    await _context.SaveChangesAsync();

                    TicketStatusVM statusVM = statusMaster.ToTicketStatusVMFromTicketStatusMaster();
                    _logger.LogInfo("Ticket Status master {TicketStatusId} updated successfully from tenant {tenantId}", statusMaster.Id, tenantId);
                    return Ok(ApiResponse<object>.SuccessResponse(statusVM, "Ticket Status master updated successfully", 200));
                }
                _logger.LogWarning("Ticket Status master {TicketStatusId} not found in database", statusMasterDto.Id != null ? statusMasterDto.Id.Value : Guid.Empty);
                return NotFound(ApiResponse<object>.ErrorResponse("Ticket Status master not found", "Ticket Status master not found", 404));
            }
            _logger.LogWarning("User sent empyt payload");
            return BadRequest(ApiResponse<object>.ErrorResponse("Sent Empty payload", "Sent Empty payload", 400));
        }

        [HttpDelete("ticket-status/{id}")]
        public async Task<IActionResult> DeleteTicketStatusMaster(Guid id)
        {
            var tenantId = _userHelper.GetTenantId();
            TicketStatusMaster? statusMaster = await _context.TicketStatusMasters.FirstOrDefaultAsync(t => t.TenantId == tenantId && t.Id == id);
            if (statusMaster != null)
            {
                if (statusMaster.IsDefault == false)
                {
                    _context.TicketStatusMasters.Remove(statusMaster);
                    await _context.SaveChangesAsync();

                    _logger.LogInfo("Ticket Status {TickeStatusId} deleted successfully from tenant {tenantId}", id, tenantId);
                    return Ok(ApiResponse<object>.SuccessResponse(new { }, "Ticket Status deleted successfully", 200));
                }
                else
                {
                    _logger.LogWarning("User tries to delete default ticket Status {TickeStatusId}", id);
                    return BadRequest(ApiResponse<object>.ErrorResponse("Can not delete default ticket Status", "Can not delete default ticket Status", 400));
                }
            }
            else
            {
                _logger.LogWarning("Ticket Status {TickeStatusId} not found in database", id);
                return NotFound(ApiResponse<object>.ErrorResponse("Ticket Status not found", "Ticket Status not found", 404));
            }
        }

        #endregion

        #region =================================================================== Ticket Type APIs ===================================================================

        [HttpGet("ticket-types")]
        public async Task<IActionResult> GetTicketTypeMaster()
        {
            Guid tenantId = _userHelper.GetTenantId();
            List<TicketTypeVM> typeVMs = new List<TicketTypeVM>();
            List<TicketTypeMaster> typeMasters = await _context.TicketTypeMasters.Where(s => s.TenantId == tenantId).ToListAsync();
            foreach (var typeMaster in typeMasters)
            {
                typeVMs.Add(typeMaster.ToTicketTypeVMFromTicketTypeMaster());
            }

            _logger.LogInfo("{count} Ticket Type records fetched successfully from tenant {tenantId}", typeVMs.Count, tenantId);
            return Ok(ApiResponse<object>.SuccessResponse(typeVMs, System.String.Format("{0} Ticket Type records fetched successfully", typeVMs.Count), 200));
        }

        [HttpPost("ticket-types")]
        public async Task<IActionResult> CreateTicketTypeMaster([FromBody] TicketTypeMasterDto typeMasterDto)
        {
            Guid tenantId = _userHelper.GetTenantId();
            if (typeMasterDto != null)
            {
                TicketTypeMaster? typeMaster = typeMasterDto.ToTicketTypeMasterFromTicketTypeMasterDto(tenantId);
                _context.TicketTypeMasters.Add(typeMaster);
                await _context.SaveChangesAsync();

                TicketTypeVM typeVM = typeMaster.ToTicketTypeVMFromTicketTypeMaster();
                _logger.LogInfo("Ticket Type master {TicketTypeId} added successfully from tenant {tenantId}", typeMaster.Id, tenantId);
                return Ok(ApiResponse<object>.SuccessResponse(typeVM, "Ticket type master added successfully", 200));

            }
            _logger.LogWarning("User sent empyt payload");
            return BadRequest(ApiResponse<object>.ErrorResponse("User sent Empty payload", "User sent Empty payload", 400));
        }

        [HttpPost("ticket-types/edit/{id}")]
        public async Task<IActionResult> UpdateTicketTypeMaster(Guid id, [FromBody] TicketTypeMasterDto typeMasterDto)
        {
            Guid tenantId = _userHelper.GetTenantId();
            if (typeMasterDto != null && typeMasterDto.Id != id)
            {
                TicketTypeMaster? typeMaster = await _context.TicketTypeMasters.AsNoTracking().FirstOrDefaultAsync(s => s.TenantId == tenantId && s.Id == typeMasterDto.Id);
                if (typeMaster != null)
                {
                    typeMaster = typeMasterDto.ToTicketTypeMasterFromTicketTypeMasterDto(tenantId);
                    _context.TicketTypeMasters.Update(typeMaster);
                    await _context.SaveChangesAsync();

                    TicketTypeVM typeVM = typeMaster.ToTicketTypeVMFromTicketTypeMaster();
                    _logger.LogInfo("Ticket Type master {TicketTypeId} updated successfully from tenant {tenantId}", typeMaster.Id, tenantId);
                    return Ok(ApiResponse<object>.SuccessResponse(typeVM, "Ticket type master updated successfully", 200));
                }
                _logger.LogWarning("Ticket type master {TicketTypeId} not found in database", typeMasterDto.Id != null ? typeMasterDto.Id.Value : Guid.Empty);
                return NotFound(ApiResponse<object>.ErrorResponse("Ticket type master not found", "Ticket type master not found", 404));
            }
            _logger.LogWarning("User sent empyt payload");
            return BadRequest(ApiResponse<object>.ErrorResponse("User sent Empty payload", "User sent Empty payload", 400));
        }

        [HttpDelete("ticket-types/{id}")]
        public async Task<IActionResult> DeleteTicketTypeMaster(Guid id)
        {
            var tenantId = _userHelper.GetTenantId();
            TicketTypeMaster? typeMaster = await _context.TicketTypeMasters.FirstOrDefaultAsync(t => t.TenantId == tenantId && t.Id == id);
            if (typeMaster != null)
            {
                if (typeMaster.IsDefault == false)
                {
                    _context.TicketTypeMasters.Remove(typeMaster);
                    await _context.SaveChangesAsync();

                    _logger.LogInfo("Ticket Type {TickeTypeId} deleted successfully from tenant {tenantId}", id, tenantId);
                    return Ok(ApiResponse<object>.SuccessResponse(new { }, "Ticket Type deleted successfully", 200));
                }
                else
                {
                    _logger.LogWarning("User tries to delete default ticket Type {TickeTypeId}", id);
                    return BadRequest(ApiResponse<object>.ErrorResponse("Can not delete default ticket Type", "Can not delete default ticket Type", 400));
                }
            }
            else
            {
                _logger.LogWarning("Ticket Type {TickeTypeId} not found in database", id);
                return NotFound(ApiResponse<object>.ErrorResponse("Ticket Type not found", "Ticket Type not found", 404));
            }
        }

        #endregion

        #region =================================================================== Ticket Priority APIs ===================================================================

        [HttpGet("ticket-priorities")]
        public async Task<IActionResult> GetTicketPriorityMaster()
        {
            Guid tenantId = _userHelper.GetTenantId();
            List<TicketPriorityVM> priorityVMs = new List<TicketPriorityVM>();
            List<TicketPriorityMaster> priorityMasters = await _context.TicketPriorityMasters.Where(s => s.TenantId == tenantId).ToListAsync();
            foreach (var priorityMaster in priorityMasters)
            {
                priorityVMs.Add(priorityMaster.ToTicketPriorityVMFromTicketPriorityMaster());
            }

            _logger.LogInfo("{count} Ticket Priority records fetched successfully from tenant {tenantId}", priorityVMs.Count, tenantId);
            return Ok(ApiResponse<object>.SuccessResponse(priorityVMs, System.String.Format("{0} Ticket Priority records fetched successfully", priorityVMs.Count), 200));
        }

        [HttpPost("ticket-priorities")]
        public async Task<IActionResult> CreateTicketPriorityMaster([FromBody] TicketPriorityMasterDto priorityMasterDto)
        {

            Guid tenantId = _userHelper.GetTenantId();
            if (priorityMasterDto != null)
            {
                TicketPriorityMaster? typeMaster = priorityMasterDto.ToTicketPriorityMasterFromTicketPriorityMasterDto(tenantId);
                _context.TicketPriorityMasters.Add(typeMaster);
                await _context.SaveChangesAsync();

                TicketPriorityVM typeVM = typeMaster.ToTicketPriorityVMFromTicketPriorityMaster();
                _logger.LogInfo("Ticket Priority master {TicketPriorityId} added successfully from tenant {tenantId}", typeMaster.Id, tenantId);
                return Ok(ApiResponse<object>.SuccessResponse(typeVM, "Ticket Priority master added successfully", 200));
            }

            _logger.LogWarning("User sent empyt payload");
            return BadRequest(ApiResponse<object>.ErrorResponse("User sent Empty payload", "User sent Empty payload", 400));
        }
        [HttpPost("ticket-priorities/edit/{id}")]
        public async Task<IActionResult> UpdateTicketPriorityMaster(Guid id, [FromBody] TicketPriorityMasterDto priorityMasterDto)
        {
            Guid tenantId = _userHelper.GetTenantId();
            if (priorityMasterDto != null && priorityMasterDto.Id != null)
            {
                TicketPriorityMaster? typeMaster = await _context.TicketPriorityMasters.AsNoTracking().FirstOrDefaultAsync(s => s.TenantId == tenantId && s.Id == priorityMasterDto.Id);
                if (typeMaster != null)
                {
                    typeMaster = priorityMasterDto.ToTicketPriorityMasterFromTicketPriorityMasterDto(tenantId);
                    _context.TicketPriorityMasters.Update(typeMaster);
                    await _context.SaveChangesAsync();

                    TicketPriorityVM typeVM = typeMaster.ToTicketPriorityVMFromTicketPriorityMaster();
                    _logger.LogInfo("Ticket Priority master {TicketPriorityId} updated successfully from tenant {tenantId}", typeMaster.Id, tenantId);
                    return Ok(ApiResponse<object>.SuccessResponse(typeVM, "Ticket Priority master updated successfully", 200));
                }
                _logger.LogWarning("Ticket Priority master {TicketPriorityId} not found in database", priorityMasterDto.Id != null ? priorityMasterDto.Id.Value : Guid.Empty);
                return NotFound(ApiResponse<object>.ErrorResponse("Ticket Priority master not found", "Ticket Priority master not found", 404));
            }
            _logger.LogWarning("User sent empyt payload");
            return BadRequest(ApiResponse<object>.ErrorResponse("User sent Empty payload", "User sent Empty payload", 400));
        }

        [HttpDelete("ticket-priorities/{id}")]
        public async Task<IActionResult> DeleteTicketPriorityMaster(Guid id)
        {
            var tenantId = _userHelper.GetTenantId();
            TicketPriorityMaster? priorityMaster = await _context.TicketPriorityMasters.FirstOrDefaultAsync(t => t.TenantId == tenantId && t.Id == id);
            if (priorityMaster != null)
            {
                if (priorityMaster.IsDefault == false)
                {
                    _context.TicketPriorityMasters.Remove(priorityMaster);
                    await _context.SaveChangesAsync();

                    _logger.LogInfo("Ticket Priority {TickePriorityId} deleted successfully from tenant {tenantId}", id, tenantId);
                    return Ok(ApiResponse<object>.SuccessResponse(new { }, "Ticket Priority deleted successfully", 200));
                }
                else
                {
                    _logger.LogWarning("User tries to delete default ticket Priority {TickePriorityId}", id);
                    return BadRequest(ApiResponse<object>.ErrorResponse("Can not delete default ticket Priority", "Can not delete default ticket Priority", 400));
                }
            }
            else
            {
                _logger.LogWarning("Ticket Priority {TickePriorityId} not found in database", id);
                return NotFound(ApiResponse<object>.ErrorResponse("Ticket Priority not found", "Ticket Priority not found", 404));
            }
        }

        #endregion

        #region =================================================================== Ticket Tag APIs ===================================================================

        [HttpGet("ticket-tags")]
        public async Task<IActionResult> GetTicketTagMaster()
        {
            Guid tenantId = _userHelper.GetTenantId();
            List<TicketTagVM> tagVMs = new List<TicketTagVM>();
            List<TicketTagMaster> tagMasters = await _context.TicketTagMasters.Where(s => s.TenantId == tenantId).ToListAsync();
            foreach (var tagMaster in tagMasters)
            {
                tagVMs.Add(tagMaster.ToTicketTagVMFromTicketTagMaster());
            }

            _logger.LogInfo("{count} Ticket Tag records fetched successfully from tenant {tenantId}", tagVMs.Count, tenantId);
            return Ok(ApiResponse<object>.SuccessResponse(tagVMs, System.String.Format("{0} Ticket Tag records fetched successfully", tagVMs.Count), 200));
        }

        [HttpPost("ticket-tags")]
        public async Task<IActionResult> CreateTicketTagMaster([FromBody] TicketTagMasterDto tagMasterDto)
        {
            Guid tenantId = _userHelper.GetTenantId();
            if (tagMasterDto != null)
            {
                TicketTagMaster? tagMaster = tagMasterDto.ToTicketTagMasterFromTicketTagMasterDto(tenantId);
                _context.TicketTagMasters.Add(tagMaster);
                await _context.SaveChangesAsync();

                TicketTagVM typeVM = tagMaster.ToTicketTagVMFromTicketTagMaster();
                _logger.LogInfo("Ticket Tag master {TicketTypeId} added successfully from tenant {tenantId}", tagMaster.Id, tenantId);
                return Ok(ApiResponse<object>.SuccessResponse(typeVM, "Ticket tag master added successfully", 200));

            }
            _logger.LogWarning("User sent empyt payload");
            return BadRequest(ApiResponse<object>.ErrorResponse("User sent Empty payload", "User sent Empty payload", 400));
        }

        [HttpPost("ticket-tags/edit/{id}")]
        public async Task<IActionResult> UpdateTicketTagMaster(Guid id, [FromBody] TicketTagMasterDto tagMasterDto)
        {
            var tenantId = _userHelper.GetTenantId();
            if (tagMasterDto != null && tagMasterDto.Id != id)
            {
                TicketTagMaster? tagMaster = await _context.TicketTagMasters.AsNoTracking().FirstOrDefaultAsync(s => s.TenantId == tenantId && s.Id == tagMasterDto.Id);
                if (tagMaster != null)
                {
                    tagMaster = tagMasterDto.ToTicketTagMasterFromTicketTagMasterDto(tenantId);
                    _context.TicketTagMasters.Update(tagMaster);
                    await _context.SaveChangesAsync();

                    TicketTagVM typeVM = tagMaster.ToTicketTagVMFromTicketTagMaster();
                    _logger.LogInfo("Ticket Tag master {TicketTypeId} updated successfully from tenant {tenantId}", tagMaster.Id, tenantId);
                    return Ok(ApiResponse<object>.SuccessResponse(typeVM, "Ticket tag master updated successfully", 200));
                }
                _logger.LogWarning("Ticket tag master {TicketTypeId} not found in database", tagMasterDto.Id != null ? tagMasterDto.Id.Value : Guid.Empty);
                return NotFound(ApiResponse<object>.ErrorResponse("Ticket tag master not found", "Ticket tag master not found", 404));
            }
            _logger.LogWarning("User sent empyt payload");
            return BadRequest(ApiResponse<object>.ErrorResponse("User sent Empty payload", "User sent Empty payload", 400));
        }

        [HttpDelete("ticket-tags/{id}")]
        public async Task<IActionResult> DeleteTicketTagMaster(Guid id)
        {
            var tenantId = _userHelper.GetTenantId();
            TicketTagMaster? tagMaster = await _context.TicketTagMasters.FirstOrDefaultAsync(t => t.TenantId == tenantId && t.Id == id);
            if (tagMaster != null)
            {
                if (tagMaster.IsDefault == false)
                {
                    _context.TicketTagMasters.Remove(tagMaster);
                    await _context.SaveChangesAsync();

                    _logger.LogInfo("Ticket Tag {TickeTagId} deleted successfully from tenant {tenantId}", id, tenantId);
                    return Ok(ApiResponse<object>.SuccessResponse(new { }, "Ticket Tag deleted successfully", 200));
                }
                else
                {
                    _logger.LogWarning("User tries to delete default ticket tag {TickeTagId}", id);
                    return BadRequest(ApiResponse<object>.ErrorResponse("Can not delete default ticket tag", "Can not delete default ticket tag", 400));
                }
            }
            else
            {
                _logger.LogWarning("Ticket Tag {TickeTagId} not found in database", id);
                return NotFound(ApiResponse<object>.ErrorResponse("Ticket tag not found", "Ticket tag not found", 404));
            }
        }

        #endregion

        #region =================================================================== Work Category APIs ===================================================================

        [HttpGet("work-categories")]
        public async Task<IActionResult> GetWorkCategoryMasterList()
        {
            Guid tenantId = _userHelper.GetTenantId();
            List<WorkCategoryMasterVM> workCategoryMasterVMs = new List<WorkCategoryMasterVM>();
            List<WorkCategoryMaster> workCategories = await _context.WorkCategoryMasters.Where(s => s.TenantId == tenantId).ToListAsync();
            foreach (var workCategory in workCategories)
            {
                workCategoryMasterVMs.Add(workCategory.ToWorkCategoryMasterVMFromWorkCategoryMaster());
            }

            _logger.LogInfo("{count} Work Category records fetched successfully from tenant {tenantId}", workCategoryMasterVMs.Count, tenantId);
            return Ok(ApiResponse<object>.SuccessResponse(workCategoryMasterVMs, System.String.Format("{0} Work Category records fetched successfully", workCategoryMasterVMs.Count), 200));
        }

        [HttpGet("work-category/{id})")]
        public async Task<IActionResult> GetWorkCategoryMaster(Guid id)
        {
            Guid tenantId = _userHelper.GetTenantId();
            WorkCategoryMaster? workCategory = await _context.WorkCategoryMasters.FirstOrDefaultAsync(s => s.TenantId == tenantId && s.Id == id);
            if (workCategory != null)
            {
                WorkCategoryMasterVM workCategoryMasterVM = workCategory.ToWorkCategoryMasterVMFromWorkCategoryMaster();
                _logger.LogInfo("{WorkCategoryId} Work Category fetched successfully from tenant {tenantId}", workCategoryMasterVM.Id ?? Guid.Empty, tenantId);
                return Ok(ApiResponse<object>.SuccessResponse(workCategoryMasterVM, "Work Category fetched successfully", 200));
            }

            _logger.LogInfo("{WorkCategoryId} Work Category not found in database", id);
            return NotFound(ApiResponse<object>.ErrorResponse("Work Category not found", "Work Category not found", 404));
        }

        [HttpPost("work-category")]
        public async Task<IActionResult> CreateWorkCategoryMaster([FromBody] WorkCategoryMasterDto workCategoryMasterDto)
        {
            Guid tenantId = _userHelper.GetTenantId();
            if (workCategoryMasterDto != null)
            {
                WorkCategoryMaster? existingWorkCategory = await _context.WorkCategoryMasters.FirstOrDefaultAsync(w => w.Name == workCategoryMasterDto.Name);
                if (existingWorkCategory != null)
                {
                    _logger.LogWarning("Work Category of name {WorkCategoryName} already exist", existingWorkCategory.Name);
                    return Conflict(ApiResponse<object>.ErrorResponse("Work Category already exist", "Work Category already exist", 409));
                }
                WorkCategoryMaster? workCategory = workCategoryMasterDto.ToWorkCategoryMasterFromWorkCategoryMasterDto(tenantId);
                WorkCategoryMasterVM workCategoryMasterVM = new WorkCategoryMasterVM();
                if (workCategory != null && workCategory.Id == Guid.Empty)
                {

                    _context.WorkCategoryMasters.Add(workCategory);
                    await _context.SaveChangesAsync();

                    workCategoryMasterVM = workCategory.ToWorkCategoryMasterVMFromWorkCategoryMaster();
                }
                _logger.LogInfo("Work category master {WorkCategoryId} added successfully from tenant {tenantId}", workCategoryMasterVM.Id ?? Guid.Empty, tenantId);
                return Ok(ApiResponse<object>.SuccessResponse(workCategoryMasterVM, "Work category master added successfully", 200));

            }
            _logger.LogWarning("User sent empyt payload");
            return BadRequest(ApiResponse<object>.ErrorResponse("User sent Empty payload", "User sent Empty payload", 400));
        }

        [HttpPost("work-category/edit/{id}")]
        public async Task<IActionResult> UpdateWorkCategoryMaster(Guid id, [FromBody] WorkCategoryMasterDto workCategoryMasterDto)
        {
            var tenantId = _userHelper.GetTenantId();
            if (workCategoryMasterDto != null && workCategoryMasterDto.Id != id)
            {
                WorkCategoryMaster? workCategory = await _context.WorkCategoryMasters.AsNoTracking().FirstOrDefaultAsync(s => s.TenantId == tenantId && s.Id == workCategoryMasterDto.Id);
                if (workCategory != null)
                {
                    if (workCategory.IsSystem)
                    {
                        _logger.LogWarning("User tries to update system-defined work category");
                        return BadRequest(ApiResponse<object>.ErrorResponse("Cannot update system-defined work", "Cannot update system-defined work", 400));
                    }
                    workCategory = workCategoryMasterDto.ToWorkCategoryMasterFromWorkCategoryMasterDto(tenantId);
                    _context.WorkCategoryMasters.Update(workCategory);
                    await _context.SaveChangesAsync();

                    WorkCategoryMasterVM workCategoryMasterVM = workCategory.ToWorkCategoryMasterVMFromWorkCategoryMaster();
                    _logger.LogInfo("Work category master {WorkCategoryId} updated successfully from tenant {tenantId}", workCategory.Id, tenantId);
                    return Ok(ApiResponse<object>.SuccessResponse(workCategoryMasterVM, "Work category master updated successfully", 200));
                }
                _logger.LogWarning("Work category master {WorkCategoryId} not found in database", workCategoryMasterDto.Id ?? Guid.Empty);
                return NotFound(ApiResponse<object>.ErrorResponse("Work category master not found", "Work category master not found", 404));
            }
            _logger.LogWarning("User sent empyt payload");
            return BadRequest(ApiResponse<object>.ErrorResponse("User sent Empty payload", "User sent Empty payload", 400));
        }

        [HttpDelete("work-category/{id}")]
        public async Task<IActionResult> DeleteWorkCategoryMaster(Guid id)
        {
            var tenantId = _userHelper.GetTenantId();
            var LoggedEmployee = await _userHelper.GetCurrentEmployeeAsync();
            WorkCategoryMaster? workCategory = await _context.WorkCategoryMasters.FirstOrDefaultAsync(t => t.TenantId == tenantId && t.Id == id);
            if (workCategory != null)
            {
                if (workCategory.IsSystem == false)
                {
                    _context.WorkCategoryMasters.Remove(workCategory);
                    await _context.SaveChangesAsync();

                    _logger.LogInfo("Work category {WorkCategoryId} deleted successfully from tenant {tenantId}", id, tenantId);
                    return Ok(ApiResponse<object>.SuccessResponse(new { }, "Work category deleted successfully", 200));
                }
                else
                {
                    _logger.LogWarning("Employee with {LoggedEmployeeId} tries to delete system-defined work category {WorkCategoryId}", LoggedEmployee.Id, id);
                    return BadRequest(ApiResponse<object>.ErrorResponse("Can not delete system-defined work category", "Can not delete system-defined work category", 400));
                }
            }
            else
            {
                _logger.LogWarning("Work category {WorkCategoryId} not found in database", id);
                return NotFound(ApiResponse<object>.ErrorResponse("Work category not found", "Work category not found", 404));
            }
        }

        #endregion

        #region =================================================================== Work Status APIs ===================================================================

        [HttpGet("work-status")]
        public async Task<IActionResult> GetWorkStatusMasterList()
        {
            var loggedInEmpoyee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.GetWorkStatusList(loggedInEmpoyee, tenantId);
            return StatusCode(response.StatusCode, response);
        }

        [HttpPost("work-status")]
        public async Task<IActionResult> CreateWorkStatusMaster([FromBody] CreateWorkStatusMasterDto createWorkStatusDto)
        {
            var loggedInEmpoyee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.CreateWorkStatus(createWorkStatusDto, loggedInEmpoyee, tenantId);
            return StatusCode(response.StatusCode, response);
        }

        [HttpPost("work-status/edit/{id}")]
        public async Task<IActionResult> UpdateWorkStatusMaster(Guid id, [FromBody] UpdateWorkStatusMasterDto updateWorkStatusDto)
        {
            var loggedInEmpoyee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.UpdateWorkStatus(id, updateWorkStatusDto, loggedInEmpoyee, tenantId);
            return StatusCode(response.StatusCode, response);
        }

        [HttpDelete("work-status/{id}")]
        public async Task<IActionResult> DeleteWorkStatusMaster(Guid id)
        {
            var loggedInEmpoyee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.DeleteWorkStatus(id, loggedInEmpoyee, tenantId);
            return StatusCode(response.StatusCode, response);
        }

        #endregion

        #region =================================================================== Contact Category APIs ===================================================================

        [HttpGet("contact-categories")]
        public async Task<IActionResult> GetContactCategoryMasterList()
        {
            var loggedInEmpoyee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.GetContactCategoriesList(loggedInEmpoyee, tenantId);
            return StatusCode(response.StatusCode, response);
        }

        [HttpGet("contact-category/{id}")]
        public async Task<IActionResult> GetContactCategoryMaster(Guid id)
        {
            var loggedInEmpoyee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.GetContactCategoryById(id, loggedInEmpoyee, tenantId);
            return StatusCode(response.StatusCode, response);

        }

        [HttpPost("contact-category")]
        public async Task<IActionResult> CreateContactCategoryMaster([FromBody] CreateContactCategoryDto contactCategoryDto)
        {
            var loggedInEmpoyee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.CreateContactCategory(contactCategoryDto, loggedInEmpoyee, tenantId);
            return StatusCode(response.StatusCode, response);

        }
        [HttpPost("contact-category/edit/{id}")]
        public async Task<IActionResult> UpdateContactCategoryMaster(Guid id, [FromBody] UpdateContactCategoryDto updateContactCategoryDto)
        {
            var loggedInEmpoyee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.UpdateContactCategory(id, updateContactCategoryDto, loggedInEmpoyee, tenantId);
            return StatusCode(response.StatusCode, response);

        }

        [HttpDelete("contact-category/{id}")]
        public async Task<IActionResult> DeletecontactCategoryMaster(Guid id)
        {
            var loggedInEmpoyee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.DeleteContactCategory(id, loggedInEmpoyee, tenantId);
            return StatusCode(response.StatusCode, response);

        }

        #endregion

        #region =================================================================== Contact Tag APIs ===================================================================

        [HttpGet("contact-tags")]
        public async Task<IActionResult> GetContactTagMasterList()
        {
            var loggedInEmpoyee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.GetContactTags(loggedInEmpoyee, tenantId);
            return StatusCode(response.StatusCode, response);

        }

        [HttpPost("contact-tag")]
        public async Task<IActionResult> CreateContactTagMaster([FromBody] CreateContactTagDto contactTagDto)
        {
            var loggedInEmpoyee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.CreateContactTag(contactTagDto, loggedInEmpoyee, tenantId);
            return StatusCode(response.StatusCode, response);

        }

        [HttpPost("contact-tag/edit/{id}")]
        public async Task<IActionResult> UpdateContactTagMaster(Guid id, [FromBody] UpdateContactTagDto updateContactTagDto)
        {
            var loggedInEmpoyee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.UpdateContactTag(id, updateContactTagDto, loggedInEmpoyee, tenantId);
            return StatusCode(response.StatusCode, response);

        }

        [HttpDelete("contact-tag/{id}")]
        public async Task<IActionResult> DeletecontactTagMaster(Guid id)
        {
            var loggedInEmpoyee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.DeleteContactTag(id, loggedInEmpoyee, tenantId);
            return StatusCode(response.StatusCode, response);

        }
        #endregion

        #region =================================================================== Expenses Category APIs ===================================================================

        [HttpGet("expenses-categories")]
        public async Task<IActionResult> GetExpenseCategoryList([FromQuery] bool isActive = true)
        {
            var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.GetExpenseCategoryListAsync(loggedInEmployee, tenantId, isActive);
            return StatusCode(response.StatusCode, response);
        }

        [HttpPost("expenses-category")]
        public async Task<IActionResult> CreateExpenseCategory([FromBody] ExpenseCategoryMasterDto dto)
        {
            var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.CreateExpenseCategoryAsync(dto, loggedInEmployee, tenantId);
            return StatusCode(response.StatusCode, response);
        }

        [HttpPut("expenses-category/edit/{id}")]
        public async Task<IActionResult> UpdateExpenseCategory(Guid id, [FromBody] ExpenseCategoryMasterDto dto)
        {
            var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.UpdateExpenseCategoryAsync(id, dto, loggedInEmployee, tenantId);
            return StatusCode(response.StatusCode, response);
        }

        [HttpDelete("expenses-category/delete/{id}")]
        public async Task<IActionResult> DeleteExpenseCategory(Guid id, [FromQuery] bool isActive = false)
        {
            var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.DeleteExpenseCategoryAsync(id, isActive, loggedInEmployee, tenantId);
            return StatusCode(response.StatusCode, response);
        }

        #endregion

        #region =================================================================== Expenses Status APIs ===================================================================

        [HttpGet("expenses-status")]
        public async Task<IActionResult> GetExpensesStatusList([FromQuery] bool isActive = true)
        {
            var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.GetExpensesStatusListAsync(loggedInEmployee, tenantId);
            return StatusCode(response.StatusCode, response);
        }

        #endregion

        #region =================================================================== Payment mode APIs ===================================================================

        [HttpGet("payment-modes")]
        public async Task<IActionResult> GetPaymentModeList([FromQuery] bool isActive = true)
        {
            var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.GetPaymentModeListAsync(loggedInEmployee, tenantId, isActive);
            return StatusCode(response.StatusCode, response);
        }

        [HttpPost("payment-mode")]
        public async Task<IActionResult> CreatePaymentMode([FromBody] PaymentModeMatserDto dto)
        {
            var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.CreatePaymentModeAsync(dto, loggedInEmployee, tenantId);
            return StatusCode(response.StatusCode, response);
        }

        [HttpPut("payment-mode/edit/{id}")]
        public async Task<IActionResult> UpdatePaymentMode(Guid id, [FromBody] PaymentModeMatserDto dto)
        {
            var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.UpdatePaymentModeAsync(id, dto, loggedInEmployee, tenantId);
            return StatusCode(response.StatusCode, response);
        }

        [HttpDelete("payment-mode/delete/{id}")]
        public async Task<IActionResult> DeletePaymentMode(Guid id, [FromQuery] bool isActive = false)
        {
            var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.DeletePaymentModeAsync(id, isActive, loggedInEmployee, tenantId);
            return StatusCode(response.StatusCode, response);
        }

        #endregion

        #region =================================================================== Document Category APIs ===================================================================

        [HttpGet("document-category/list")]
        public async Task<IActionResult> GetDocumentCategoryMasterList([FromQuery] Guid? entityTypeId)
        {
            var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.GetDocumentCategoryMasterListAsync(entityTypeId, loggedInEmployee, tenantId);
            return StatusCode(response.StatusCode, response);
        }

        [HttpPost("document-category")]
        public async Task<IActionResult> CreateDocumentCategoryMaster([FromBody] CreateDocumentCategoryDto dto)
        {
            var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.CreateDocumentCategoryMasterAsync(dto, loggedInEmployee, tenantId);
            return StatusCode(response.StatusCode, response);
        }

        [HttpPut("document-category/edit/{id}")]
        public async Task<IActionResult> UpdateDocumentCategoryMaster(Guid id, [FromBody] CreateDocumentCategoryDto dto)
        {
            var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.UpdateDocumentCategoryMasterAsync(id, dto, loggedInEmployee, tenantId);
            return StatusCode(response.StatusCode, response);
        }

        [HttpDelete("document-category/delete/{id}")]
        public async Task<IActionResult> DeleteDocumentCategoryMaster(Guid id)
        {
            var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.DeleteDocumentCategoryMasterAsync(id, loggedInEmployee, tenantId);
            return StatusCode(response.StatusCode, response);
        }

        #endregion

        #region =================================================================== Document Type APIs ===================================================================

        [HttpGet("document-type/list")]
        public async Task<IActionResult> GetDocumentTypeMasterList([FromQuery] Guid? documentCategoryId)
        {
            var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.GetDocumentTypeMasterListAsync(documentCategoryId, loggedInEmployee, tenantId);
            return StatusCode(response.StatusCode, response);
        }

        [HttpPost("document-type")]
        public async Task<IActionResult> CreateDocumentTypeMaster([FromBody] CreateDocumentTypeDto dto)
        {
            var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.CreateDocumentTypeMasterAsync(dto, loggedInEmployee, tenantId);
            return StatusCode(response.StatusCode, response);
        }

        [HttpPut("document-type/edit/{id}")]
        public async Task<IActionResult> UpdateDocumentTypeMaster(Guid id, [FromBody] CreateDocumentTypeDto dto)
        {
            var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.UpdateDocumentTypeMasterAsync(id, dto, loggedInEmployee, tenantId);
            return StatusCode(response.StatusCode, response);
        }

        [HttpDelete("document-type/delete/{id}")]
        public async Task<IActionResult> DeleteDocumentTypeMaster(Guid id, [FromQuery] bool isActive = false)
        {
            var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.DeleteDocumentTypeMasterAsync(id, isActive, loggedInEmployee, tenantId);
            return StatusCode(response.StatusCode, response);
        }

        #endregion

        #region =================================================================== Payment Adjustment Head APIs ===================================================================
        [HttpGet("payment-adjustment-head/list")]
        public async Task<IActionResult> GetpaymentAdjustmentHeadsList([FromQuery] bool isActive = true)
        {
            var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.GetPaymentAdjustmentHeadListAsync(isActive, loggedInEmployee, tenantId);
            return StatusCode(response.StatusCode, response);
        }
        [HttpPost("payment-adjustment-head")]
        public async Task<IActionResult> CreatePaymentAdjustmentHead([FromBody] PaymentAdjustmentHeadDto dto)
        {
            var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.CreatePaymentAdjustmentHeadAsync(dto, loggedInEmployee, tenantId);
            return StatusCode(response.StatusCode, response);
        }

        [HttpPut("payment-adjustment-head/edit/{id}")]
        public async Task<IActionResult> UpdatePaymentAdjustmentHead(Guid id, [FromBody] PaymentAdjustmentHeadDto dto)
        {
            var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.UpdatePaymentAdjustmentHeadAsync(id, dto, loggedInEmployee, tenantId);
            return StatusCode(response.StatusCode, response);
        }

        [HttpDelete("payment-adjustment-head/delete/{id}")]
        public async Task<IActionResult> DeletePaymentAdjustmentHead(Guid id, [FromQuery] bool isActive = false)
        {
            var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
            var response = await _masterService.DeletePaymentAdjustmentHeadAsync(id, isActive, loggedInEmployee, tenantId);
            return StatusCode(response.StatusCode, response);
        }
        #endregion
    }
}
