using System.Collections.Generic;
using System.Linq;
using BO.AppServer.Data.Entity;
using Quadarax.Foundation.Core.Data;
using Quadarax.Foundation.Core.Data.Domain;
using Quadarax.Foundation.Core.Data.Interface.Domain;
using Quadarax.Foundation.Core.Data.Repository;

namespace BO.AppServer.Data.Repository
{
    public class ArtifactRepo : EntityRepository<long, Artifact>
    {
        public ArtifactRepo(IUnitOfWork<DataDomain> unitOfWork) : base(unitOfWork)
        {
            DefaultIncludes.Add("MimeType");
        }

        public Artifact GetArtifact(long metadocumentId, long artifactId)
        {
            return Query(new Paging()).FirstOrDefault(x => x.MetadocumentId == metadocumentId && x.Id== artifactId);
        }

        public IEnumerable<Artifact> GetArtifacts(long metadocumentId)
        {
            return Query(new Paging()).Where(x => x.MetadocumentId == metadocumentId);
        }


        public Artifact GetArtifactByName(long metadocumentId, string nameWithoutExtension, string extension)
        {
            return Query(new Paging()).FirstOrDefault(x => x.Id == metadocumentId && x.Name.ToLower() == nameWithoutExtension.ToLower() && x.Extension.ToLower() == extension.ToLower());
        }

    }
}
