package appservice

import (
	"go-admin/app/admin/models"
	"go-admin/app/admin/service/dto"
	memberrenwalconfigstatus "go-admin/common/const/dicts/member_renwal_config_status"
	memberrenwalisvisible "go-admin/common/const/dicts/member_renwal_isvisible"
	statuscode "go-admin/common/status_code"

	"github.com/go-admin-team/go-admin-core/sdk/service"
)

type MemberRenwalConfigAppService struct {
	service.Service
}

func (e *MemberRenwalConfigAppService) GetList(language string) ([]dto.MemberRenwalConfigAppResp, int) {
	var datas []models.MemberRenwalConfig
	result := make([]dto.MemberRenwalConfigAppResp, 0)
	if err := e.Orm.Model(&models.MemberRenwalConfig{}).Where(" status =? AND is_visible =?",
		memberrenwalconfigstatus.ENABLE, memberrenwalisvisible.IsVisibleYes).
		Order("sort asc").Find(&datas).Error; err != nil {
		return result, statuscode.ServerError
	}

	for _, v := range datas {
		item := dto.MemberRenwalConfigAppResp{
			Id:            v.Id,
			PackageName:   v.PackageName,
			OriginalPrice: v.OriginalPrice,
			DiscountPrice: v.DiscountPrice,
			DurationDay:   v.DurationDay,
			Remark:        v.Remark,
		}

		if language != "zh_CN" {
			item.PackageName = v.PackageNameEn
		}
		result = append(result, item)
	}

	return result, statuscode.OK
}
