package internal

import (
	"context"
	"golang.source-fellows.com/pattern/adapter/internal/model"
)

type ContractList struct {
	stores []ContractStore
}

func NewContractList(stores []ContractStore) *ContractList {
	return &ContractList{stores: stores}
}

func (l ContractList) GetAllContracts(
	ctx context.Context,
	customer model.Customer) ([]model.Contract, error) {

	var allContracts []model.Contract
	for _, store := range l.stores {
		contracts, err := store.GetAllContracts(ctx, customer)
		if err != nil {
			return nil, err
		}
		allContracts = append(allContracts, contracts...)
	}
	return allContracts, nil
}
