package repository

import (
	"actatempus_backend/internal/domain/data"
	"actatempus_backend/internal/domain/entities"
	"actatempus_backend/internal/domain/repository"
	"context"

	E "github.com/IBM/fp-go/either"
	F "github.com/IBM/fp-go/function"

)

// ProjectRepositoryImpl implements the ProjectRepository interface.
type ProjectRepositoryImpl struct {
	dataSource data.ProjectDataSource
}

// NewProjectRepository creates a new instance of ProjectRepositoryImpl.
func NewProjectRepository(dataSource data.ProjectDataSource) repository.ProjectRepository {
	return &ProjectRepositoryImpl{dataSource: dataSource}
}

// Create delegates the creation of a project to the data source.
func (r *ProjectRepositoryImpl) Create(ctx context.Context) func(project entities.ProjectCreate) E.Either[error, entities.Project] {
	return F.Curry2(r.dataSource.Create)(ctx)
}

// FindByID delegates fetching a project by ID to the data source.
func (r *ProjectRepositoryImpl) FindByID(ctx context.Context) func(id string) E.Either[error, entities.Project] {
	return F.Curry2(r.dataSource.FindByID)(ctx)
}

// FindByUserID delegates fetching projects by user ID to the data source.
func (r *ProjectRepositoryImpl) FindByUserID(ctx context.Context) func(userID string) E.Either[error, []entities.Project] {
	return F.Curry2(r.dataSource.FindByUserID)(ctx)
}

// Update delegates updating a project to the data source.
func (r *ProjectRepositoryImpl) Update(ctx context.Context) func(project entities.ProjectUpdate) E.Either[error, entities.Project] {
	return F.Curry2(r.dataSource.Update)(ctx)
}

// Delete delegates deleting a project to the data source.
func (r *ProjectRepositoryImpl) Delete(ctx context.Context) func(id string) E.Either[error, entities.Project] {
	return F.Curry2(r.dataSource.Delete)(ctx)
}

// FindAll delegates fetching all projects to the data source.
func (r *ProjectRepositoryImpl) FindAll(ctx context.Context) E.Either[error, []entities.Project] {
	return F.Curry1(r.dataSource.FindAll)(ctx)
}
