using HospitalManagementSystem.Dtos;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;

namespace HospitalManagementSystem.Departments
{
    public class DepartmentAppService : HospitalManagementSystemAppService, IDepartmentAppService
    {
        private readonly IRepository<Department, Guid> _departmentRepository;
        public DepartmentAppService(IRepository<Department, Guid> departmentRepository)
        {
            _departmentRepository = departmentRepository;
        }
        public async Task<List<DepartmentDto>> GetAsync()
        {
            var departmentDtos = new List<DepartmentDto>();
            var data = await _departmentRepository.GetListAsync();
            departmentDtos = ObjectMapper.Map<List<Department>, List<DepartmentDto>>(data);
            return departmentDtos;
        }

        public async Task<DepartmentDto> CreateAsync(CreateDepartmentDto input)
        {
            var department = new Department(Guid.NewGuid(), input.DepartmentNo, input.DepartmentName, input.DepartmentDate, input.DepartmentHead, "Active", input.Description);
            await _departmentRepository.InsertAsync(department);
            return ObjectMapper.Map<Department, DepartmentDto>(department);
        }
    }
}
