package tenant

import (
	"context"

	"github.com/rede5/gohorsejobs/backend/internal/core/dto"
	"github.com/rede5/gohorsejobs/backend/internal/core/ports"
)

type ListCompaniesUseCase struct {
	companyRepo ports.CompanyRepository
}

func NewListCompaniesUseCase(companyRepo ports.CompanyRepository) *ListCompaniesUseCase {
	return &ListCompaniesUseCase{
		companyRepo: companyRepo,
	}
}

func (uc *ListCompaniesUseCase) Execute(ctx context.Context) ([]dto.CompanyResponse, error) {
	companies, err := uc.companyRepo.FindAll(ctx)
	if err != nil {
		return nil, err
	}

	response := []dto.CompanyResponse{}
	for _, c := range companies {
		response = append(response, dto.CompanyResponse{
			ID:        c.ID,
			Name:      c.Name,
			Status:    c.Status,
			CreatedAt: c.CreatedAt,
		})
	}

	return response, nil
}
