using Lactose.Context;
using Lactose.Models;

namespace Lactose.Repositories;

public class FolderRepository(LactoseDbContext context) : IFolderRepository {
    public void Create(Folder folder) => context.Folders.Add(folder);

    public void Update(Guid id, Folder folder) {
        var origFolder = context.Folders.Find(id);

        if (origFolder != null) {
            origFolder.BasePath = folder.BasePath;
            origFolder.Active   = folder.Active;
            context.Folders.Update(origFolder);
            context.SaveChanges();
        }
    }

    public void Delete(Guid id) {
        var folder = context.Folders.Find(id);
        if(folder != null) context.Folders.Remove(folder);
    }

    public Folder? Get(Guid id) => context.Folders.Find(id);
    
    public IEnumerable<Folder> GetAll() => context.Folders;
}
