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"
)

// ProjectTaskRepositoryImpl implements the ProjectTaskRepository interface.
type ProjectTaskRepositoryImpl struct {
	dataSource data.ProjectTaskDataSource
}

// NewProjectTaskRepository creates a new instance of ProjectTaskRepositoryImpl.
func NewProjectTaskRepository(dataSource data.ProjectTaskDataSource) repository.ProjectTaskRepository {
	return &ProjectTaskRepositoryImpl{dataSource: dataSource}
}

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

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

// FindByProjectID delegates fetching project tasks by project ID to the data source.
func (r *ProjectTaskRepositoryImpl) FindByProjectID(ctx context.Context) func(projectID string) E.Either[error, []entities.ProjectTask] {
	return F.Curry2(r.dataSource.FindByProjectID)(ctx)
}

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

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

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