using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Domain.Aggregates.Stores;
using Domain.Aggregates.Stores.Data;
using Microsoft.EntityFrameworkCore;

namespace Persistence.Repositories.Aggregates.Stores;

public class StoreRepository(DatabaseContext databaseContext) : IStoreRepository
{
    public async Task AddAsync(Store store)
    {
        await databaseContext.AddAsync(store);
    }

    public async Task<List<Store>> GetAllAsync()
    {
        var store =
            await databaseContext.Stores
            .Where(x => x.IsDeleted == false)
            .ToListAsync();

        return store;
    }

    public async Task<Store?> GetAsync(Guid storeId)
    {
        var store =
            await databaseContext.Stores
            .Where(x => x.IsDeleted == false)
            .Where(x => x.Id == storeId)
            .FirstOrDefaultAsync();

        return store;
    }

    public void Remove(Store store)
    {
        store.Delete();
    }

    public async Task SaveChangesAsync()
    {
        await databaseContext.SaveChangesAsync();
    }
}
