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

namespace Persistence.Repositories.Aggregates.Products;

public class ProductRepository(DatabaseContext databaseContext):IProductRepository
{
    public async Task AddAsync(Product product)
    {
        await databaseContext.AddAsync(product);
    }

    public async Task<List<Product>> GetAllAsync()
    {
        var products =
            await databaseContext.Products
            .Where(x => x.IsDeleted == false)
            .ToListAsync();

        return products;
    }

    public async Task<Product?> GetAsync(Guid productId)
    {
        var product =
            await databaseContext.Products
            .Where(x => x.IsDeleted == false)
            .Where(x => x.Id == productId)
            .FirstOrDefaultAsync();

        return product;
    }

    public void Remove(Product product)
    {
        product.Delete();
    }

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