package merchant

import (
	"context"

	"kami/api/commonApi"
	v1 "kami/api/merchant/v1"
	"kami/internal/model"
	"kami/internal/service"
)

func (c *ControllerV1) MerchantConfigList(ctx context.Context, req *v1.MerchantConfigListReq) (res *v1.MerchantConfigListRes, err error) {
	res = &v1.MerchantConfigListRes{}
	merchant := service.Merchant()
	total, list, err := merchant.List(ctx, model.MerchantListParamsInput{MerchantListParamsReq: req.MerchantListParamsReq})
	if err != nil {
		return res, err
	}

	resList := make([]v1.MerchantInfoRecord, 0)
	for _, i := range list {
		resList = append(resList, i.MerchantInfoRecord)
	}

	res = &v1.MerchantConfigListRes{
		CommonPageRes: commonApi.CommonPageRes[v1.MerchantInfoRecord]{
			Total: total,
			CommonDataRes: commonApi.CommonDataRes[v1.MerchantInfoRecord]{
				List: resList,
			},
		},
	}
	return res, err
}
