using Baya.Application.Contracts.Persistence;

namespace Baya.Infrastructure.Persistence.Repositories.Common;

public class UnitOfWork : IUnitOfWork
{
    private readonly ApplicationDbContext _db;

    public IUserRefreshTokenRepository UserRefreshTokenRepository { get; }
    public IUserSessionRepository UserSessionRepository { get; }
    public IUserAccountRepository UserAccountRepository { get; }
    public INurseProfileRepository NurseProfileRepository { get; }
    public ICustomerProfileRepository CustomerProfileRepository { get; }
    public IPatientRepository PatientRepository { get; }
    public INurseBankAccountRepository NurseBankAccountRepository { get; }
    public IGeoRepository GeoRepository { get; }
    public INurseServiceAreaRepository NurseServiceAreaRepository { get; }
    public ICustomerAddressRepository CustomerAddressRepository { get; }
    public ICatalogRepository CatalogRepository { get; }
    public INurseServiceVariantRepository NurseServiceVariantRepository { get; }
    public IVerificationRepository VerificationRepository { get; }
    public IBookingRequestRepository BookingRequestRepository { get; }
    public IBookingRepository BookingRepository { get; }
    public ICancellationPolicyRepository CancellationPolicyRepository { get; }
    public IPaymentRepository PaymentRepository { get; }
    public IRefundRepository RefundRepository { get; }
    public IInvoiceRepository InvoiceRepository { get; }
    public IBnplRepository BnplRepository { get; }
    public IPayoutRepository PayoutRepository { get; }
    public IReviewRepository ReviewRepository { get; }
    public IPatientCareRecordRepository PatientCareRecordRepository { get; }
    public ITicketRepository TicketRepository { get; }
    public IPartnerCenterRepository PartnerCenterRepository { get; }

    public UnitOfWork(ApplicationDbContext db)
    {
        _db = db;
        UserRefreshTokenRepository = new UserRefreshTokenRepository(_db);
        UserSessionRepository = new UserSessionRepository(_db);
        UserAccountRepository = new UserAccountRepository(_db);
        NurseProfileRepository = new NurseProfileRepository(_db);
        CustomerProfileRepository = new CustomerProfileRepository(_db);
        PatientRepository = new PatientRepository(_db);
        NurseBankAccountRepository = new NurseBankAccountRepository(_db);
        GeoRepository = new GeoRepository(_db);
        NurseServiceAreaRepository = new NurseServiceAreaRepository(_db);
        CustomerAddressRepository = new CustomerAddressRepository(_db);
        CatalogRepository = new CatalogRepository(_db);
        NurseServiceVariantRepository = new NurseServiceVariantRepository(_db);
        VerificationRepository = new VerificationRepository(_db);
        BookingRequestRepository = new BookingRequestRepository(_db);
        BookingRepository = new BookingRepository(_db);
        CancellationPolicyRepository = new CancellationPolicyRepository(_db);
        PaymentRepository = new PaymentRepository(_db);
        RefundRepository = new RefundRepository(_db);
        InvoiceRepository = new InvoiceRepository(_db);
        BnplRepository = new BnplRepository(_db);
        PayoutRepository = new PayoutRepository(_db);
        ReviewRepository = new ReviewRepository(_db);
        PatientCareRecordRepository = new PatientCareRecordRepository(_db);
        TicketRepository = new TicketRepository(_db);
        PartnerCenterRepository = new PartnerCenterRepository(_db);
    }

    public Task CommitAsync()
    {
        return _db.SaveChangesAsync();
    }

    public ValueTask RollBackAsync()
    {
        _db.ChangeTracker.Clear();
        return ValueTask.CompletedTask;
    }
}
