namespace MyOffice.Data.Repositories.Account;

using Microsoft.EntityFrameworkCore;
using Models.Accounts;
using MyOffice.DbContext;

public class AccountAccountCategoryRepository : AppRepository<AccountAccountCategory>, IAccountAccountCategoryRepository
{
	public AccountAccountCategoryRepository(AppDbContext context) : base(context)
	{
	}

	public List<AccountAccountCategory> Get(Guid userId, Guid accountId, Guid categoryId)
	{
		return _context.AccountAccountCategories
			.Include(x => x.Account)
			.Include(x => x.Category)
			.Where(x => x.AccountId == accountId && x.CategoryId == categoryId && x.Category.UserId == userId)
			.ToList();
	}

	public async Task<List<AccountAccountCategory>> GetAsync(
		Guid userId,
		Guid accountId,
		Guid categoryId,
		CancellationToken cancellationToken = default
	)
	{
		return await _context.AccountAccountCategories
			.Include(x => x.Account)
			.Include(x => x.Category)
			.Where(x => x.AccountId == accountId && x.CategoryId == categoryId && x.Category.UserId == userId)
			.ToListAsync(cancellationToken);
	}

	public bool Remove(AccountAccountCategory accountAccountCategory)
	{
		return RemoveBase(accountAccountCategory) > 0;
	}

	public async Task<bool> RemoveAsync(AccountAccountCategory accountAccountCategory, CancellationToken cancellationToken = default)
	{
		return await RemoveBaseAsync(accountAccountCategory, cancellationToken) > 0;
	}

	public bool Add(AccountAccountCategory accountAccountCategory)
	{
		return AddBase(accountAccountCategory) > 0;
	}

	public async Task<bool> AddAsync(AccountAccountCategory accountAccountCategory, CancellationToken cancellationToken = default)
	{
		return await AddBaseAsync(accountAccountCategory, cancellationToken) > 0;
	}
}