using Microsoft.EntityFrameworkCore;
using Domain.Entities;
using Models.Interfaces;
using Models.Models;

namespace Models.Repositories
{
    public class PhLSMLookUpRepository(PhronCareOperationsHubContext context) : IPhLSMLookUpRepository
    {
        private readonly PhronCareOperationsHubContext _context = context;

        public async Task<IEnumerable<ELookUpItem>> ProductDivisionsAsync(string filter, int limit = 10)
            => await _context.PhLsmProductDivisions
                .Where(d =>
                    d.Code.Contains(filter) ||
                    d.Name.Contains(filter) ||
                    d.Description.Contains(filter))
                .OrderBy(d => d.Code)
                .Select(d => new ELookUpItem
                {
                    Id = d.Id,
                    Nombre = d.Code + " | " + d.Name
                })
                .Take(limit)
                .ToListAsync();

        public async Task<IEnumerable<ELookUpItem>> UnitsOfMeasureAsync(string filter, int limit = 10)
            => await _context.PhLsmUnitOfMeasures
                .Where(u => u.Code.Contains(filter) || u.Name.Contains(filter))
                .OrderBy(u => u.Code)
                .Select(u => new ELookUpItem
                {
                    Id = u.Id,
                    Nombre = u.Code + " | " + u.Name
                })
                .Take(limit)
                .ToListAsync();
    }
}
