package card_apple_account

import (
	"context"

	"kami/internal/consts"
	"kami/internal/dao"
	"kami/internal/model/do"
	"kami/utility/config"

	"github.com/gogf/gf/v2/database/gdb"
)

func (a *sAppleAccount) ModifyStatus(ctx context.Context, id string, status consts.AppleAccountStatus, tx gdb.TX) (err error) {
	m := dao.V1CardAppleAccountInfo.Ctx(ctx).DB(config.GetDatabaseV1())
	if tx != nil {
		m = m.TX(tx)
	}
	_, err = m.Where(dao.V1CardAppleAccountInfo.Columns().Id, id).Update(do.V1CardAppleAccountInfo{
		Status: status,
	})
	return
}

// CheckAllAccountIsNormal 判断当前用户上传是否有账户可用
func (a *sAppleAccount) CheckAllAccountIsNormal(ctx context.Context, createdUserId string) (isNormal bool, err error) {
	num, err := dao.V1CardAppleAccountInfo.Ctx(ctx).DB(config.GetDatabaseV1()).
		Where(dao.V1CardAppleAccountInfo.Columns().CreatedUserId, createdUserId).
		Where(dao.V1CardAppleAccountInfo.Columns().Status, consts.AppleAccountNormal).Count()
	return num > 0, err
}
