package service

import (
	"context"
	"github.com/fonchain_enterprise/fonchain-approval/api/approval"
	"github.com/fonchain_enterprise/fonchain-approval/pkg/model"
)

func (a *ApprovalProvider) GetName(ctx context.Context, in *approval.GetNameRequest) (*approval.GetNameResponse, error) {
	settings := make([]*model.FinancialFormSetting, 0)

	err := model.DB.Model(&model.FinancialFormSetting{}).Where("setting_type = ?", in.SettingType).Find(&settings).Error
	if err != nil {
		return nil, err
	}
	response := new(approval.GetNameResponse)
	for i := 0; i < len(settings); i++ {
		response.Name = append(response.Name, settings[i].Name)
	}
	return response, nil
}