package service

import (
	"context"

	patientdata "wucher/internal/domain/patient_data"
)

type PatientDataService struct {
	repo patientdata.Repository
}

func NewPatientDataService(repo patientdata.Repository) *PatientDataService {
	return &PatientDataService{repo: repo}
}

func (s *PatientDataService) Create(ctx context.Context, row *patientdata.PatientData) error {
	return s.repo.Create(ctx, row)
}

func (s *PatientDataService) Update(ctx context.Context, row *patientdata.PatientData) error {
	return s.repo.Update(ctx, row)
}

func (s *PatientDataService) Delete(ctx context.Context, id []byte, deletedBy []byte) error {
	return s.repo.Delete(ctx, id, deletedBy)
}

func (s *PatientDataService) GetByID(ctx context.Context, id []byte) (*patientdata.PatientData, error) {
	return s.repo.GetByID(ctx, id)
}

func (s *PatientDataService) List(ctx context.Context, filter, sort string, limit, offset int) ([]patientdata.PatientData, int64, error) {
	return s.repo.List(ctx, filter, normalizePatientDataSort(sort), limit, offset)
}

func normalizePatientDataSort(sort string) string {
	return normalizeSortByRules(sort,
		sortField("family_name"),
		sortField("first_name"),
		sortField("birth_date"),
		sortField("gender"),
		sortField("created_at"),
		sortField("updated_at"),
	)
}
