package auditloghandler

import (
	"fmt"

	"github.com/pingcap/dbaas/billing2/forms"
	"github.com/tidbcloud/tiinf/sdk/auditlog"
)

func StripePaymentMethod2AuditLogDetails(m *forms.StripePaymentMethod) (ret *auditlog.Details) {
	defer recoverIfPanic()
	return &auditlog.Details{
		"payment_method_id": m.ID,
		"country":           m.Card.Country,
		"address1":          m.BillingDetails.Address.Line1,
		"address2":          m.BillingDetails.Address.Line2,
		"city":              m.BillingDetails.Address.City,
		"state":             m.BillingDetails.Address.State,
		"name":              m.BillingDetails.Name,
		"card_number_last4": m.Card.Last4,
		"expiration_date":   fmt.Sprintf("%d/%d", m.Card.ExpMonth, m.Card.ExpYear),
	}
}

func BillingInformation2AuditLogDetails(i *forms.BillingInformation) (ret *auditlog.Details) {
	defer recoverIfPanic()
	return &auditlog.Details{
		"country":     i.CountryCode,
		"address1":    i.Line1,
		"address2":    i.Line2,
		"city":        i.City,
		"state":       i.State,
		"postal_code": i.PostalCode,
		"tax_vat":     i.TaxID,
	}
}

func Contract2AuditLogDetails(contract *forms.Contract, action string) (ret *auditlog.Details) {
	defer recoverIfPanic()
	return &auditlog.Details{
		"contract_id":  contract.ContractID,
		"created_time": contract.CreatedAt,
		"actions":      action,
		"status":       contract.Status,
	}
}

func SupportPlan2AuditLogDetails(s *forms.SupportPlan) (ret *auditlog.Details) {
	defer recoverIfPanic()
	return &auditlog.Details{
		"support_plan_id":          s.SupportPlanID,
		"fixed_charge_price":       s.FixedChargePrice,
		"support_price_percentage": s.SupportPricePercentage,
		"type":                     s.Type,
		"level":                    s.Level,
	}
}
