package ledgerconv

import (
	"strings"

	ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1"
)

func ParseAccountType(value string) (ledgerv1.AccountType, bool) {
	switch strings.ToUpper(strings.TrimSpace(value)) {
	case "ACCOUNT_TYPE_ASSET", "ASSET":
		return ledgerv1.AccountType_ACCOUNT_TYPE_ASSET, true
	case "ACCOUNT_TYPE_LIABILITY", "LIABILITY":
		return ledgerv1.AccountType_ACCOUNT_TYPE_LIABILITY, true
	case "ACCOUNT_TYPE_REVENUE", "REVENUE":
		return ledgerv1.AccountType_ACCOUNT_TYPE_REVENUE, true
	case "ACCOUNT_TYPE_EXPENSE", "EXPENSE":
		return ledgerv1.AccountType_ACCOUNT_TYPE_EXPENSE, true
	case "ACCOUNT_TYPE_UNSPECIFIED", "UNSPECIFIED":
		return ledgerv1.AccountType_ACCOUNT_TYPE_UNSPECIFIED, true
	default:
		return ledgerv1.AccountType_ACCOUNT_TYPE_UNSPECIFIED, false
	}
}

func ParseAccountStatus(value string) (ledgerv1.AccountStatus, bool) {
	switch strings.ToUpper(strings.TrimSpace(value)) {
	case "ACCOUNT_STATUS_ACTIVE", "ACTIVE":
		return ledgerv1.AccountStatus_ACCOUNT_STATUS_ACTIVE, true
	case "ACCOUNT_STATUS_FROZEN", "FROZEN":
		return ledgerv1.AccountStatus_ACCOUNT_STATUS_FROZEN, true
	case "ACCOUNT_STATUS_UNSPECIFIED", "UNSPECIFIED":
		return ledgerv1.AccountStatus_ACCOUNT_STATUS_UNSPECIFIED, true
	default:
		return ledgerv1.AccountStatus_ACCOUNT_STATUS_UNSPECIFIED, false
	}
}

func ParseAccountRole(value string) (ledgerv1.AccountRole, bool) {
	switch strings.ToUpper(strings.TrimSpace(value)) {
	case "ACCOUNT_ROLE_OPERATING", "OPERATING":
		return ledgerv1.AccountRole_ACCOUNT_ROLE_OPERATING, true
	case "ACCOUNT_ROLE_HOLD", "HOLD":
		return ledgerv1.AccountRole_ACCOUNT_ROLE_HOLD, true
	case "ACCOUNT_ROLE_TRANSIT", "TRANSIT":
		return ledgerv1.AccountRole_ACCOUNT_ROLE_TRANSIT, true
	case "ACCOUNT_ROLE_SETTLEMENT", "SETTLEMENT":
		return ledgerv1.AccountRole_ACCOUNT_ROLE_SETTLEMENT, true
	case "ACCOUNT_ROLE_CLEARING", "CLEARING":
		return ledgerv1.AccountRole_ACCOUNT_ROLE_CLEARING, true
	case "ACCOUNT_ROLE_PENDING", "PENDING":
		return ledgerv1.AccountRole_ACCOUNT_ROLE_PENDING, true
	case "ACCOUNT_ROLE_RESERVE", "RESERVE":
		return ledgerv1.AccountRole_ACCOUNT_ROLE_RESERVE, true
	case "ACCOUNT_ROLE_LIQUIDITY", "LIQUIDITY":
		return ledgerv1.AccountRole_ACCOUNT_ROLE_LIQUIDITY, true
	case "ACCOUNT_ROLE_FEE", "FEE":
		return ledgerv1.AccountRole_ACCOUNT_ROLE_FEE, true
	case "ACCOUNT_ROLE_CHARGEBACK", "CHARGEBACK":
		return ledgerv1.AccountRole_ACCOUNT_ROLE_CHARGEBACK, true
	case "ACCOUNT_ROLE_ADJUSTMENT", "ADJUSTMENT":
		return ledgerv1.AccountRole_ACCOUNT_ROLE_ADJUSTMENT, true
	case "ACCOUNT_ROLE_UNSPECIFIED", "UNSPECIFIED", "":
		return ledgerv1.AccountRole_ACCOUNT_ROLE_UNSPECIFIED, true
	default:
		return ledgerv1.AccountRole_ACCOUNT_ROLE_UNSPECIFIED, false
	}
}

func IsAccountTypeUnspecified(value string) bool {
	switch strings.ToUpper(strings.TrimSpace(value)) {
	case "", "ACCOUNT_TYPE_UNSPECIFIED", "UNSPECIFIED":
		return true
	default:
		return false
	}
}

func IsAccountStatusUnspecified(value string) bool {
	switch strings.ToUpper(strings.TrimSpace(value)) {
	case "", "ACCOUNT_STATUS_UNSPECIFIED", "UNSPECIFIED":
		return true
	default:
		return false
	}
}

func IsAccountRoleUnspecified(value string) bool {
	switch strings.ToUpper(strings.TrimSpace(value)) {
	case "", "ACCOUNT_ROLE_UNSPECIFIED", "UNSPECIFIED":
		return true
	default:
		return false
	}
}
