using IWS5.DatabaseAccess.Interfaces;
using IWS5.DatabaseAccess.IwsDataContext;
using IWS5.DatabaseAccess.IwsDataModels;
using Microsoft.EntityFrameworkCore;

namespace IWS5.DatabaseAccess.Repositories;

public class DocumentCabinetDefinitionRepository : IWSRepository<AtdocumentCabinetDef>,
    IDocumentCabinetDefinitionRepository
{
    private readonly GreenfieldPd2015Context context;

    public DocumentCabinetDefinitionRepository(GreenfieldPd2015Context context) : base(context)
    {
        this.context = context;
    }

    public async Task<List<AtdocumentCabinetDef>> GetDocumentCabinetDefinitions(List<Guid> templateIds)
    {
        var query = context.AtdocumentCabinetDefs
            .Where(docDef => EF.Constant(templateIds).Contains(docDef.ObjectId));

        var data = await query
            .Select(docDef => new AtdocumentCabinetDef
            {
                FieldId = docDef.FieldId,
                FieldName = docDef.FieldName,
                FieldDataType = docDef.FieldDataType,
                ObjectId = docDef.ObjectId
            }).ToListAsync();

        return data;
    }
}