package app

import (
	"encoding/json"

	"code.tnxs.net/taxnexus/lib/api/crm/crm_models"
	"code.tnxs.net/taxnexus/lib/api/ops/ops_models"
)

// Address address struct
type Address struct {
	City        string
	Country     string
	CountryCode string
	PostalCode  string
	State       string
	StateCode   string
	Street      string
}

// ToString returns the full address in a string
func (obj *Address) ToString() string {
	return obj.Street + " " +
		obj.City + " " +
		obj.State + " " +
		obj.PostalCode
}

// MarshalToJSON returns a JSON string representation of the address
func (obj *Address) MarshalToJSON() *string {
	bytes, _ := json.Marshal(obj)
	str := string(bytes)
	return &str
}

// MarshalToCrm converts a first class object to swagger
func (obj *Address) MarshalToCrm() *crm_models.Address {
	if obj == nil {
		return nil
	}
	return &crm_models.Address{
		City:        obj.City,
		Country:     obj.Country,
		CountryCode: obj.CountryCode,
		PostalCode:  obj.PostalCode,
		State:       obj.State,
		StateCode:   obj.StateCode,
		Street:      obj.Street,
	}
}

// MarshalToOps converts a first class object to swagger
func (obj *Address) MarshalToOps() *ops_models.Address {
	if obj == nil {
		return nil
	}
	return &ops_models.Address{
		City:        obj.City,
		Country:     obj.Country,
		CountryCode: obj.CountryCode,
		PostalCode:  obj.PostalCode,
		State:       obj.State,
		StateCode:   obj.StateCode,
		Street:      obj.Street,
	}
}

// UnMarshalCrmAddress converts a first class object to swagger
func UnMarshalCrmAddress(s *crm_models.Address) *Address {
	if s == nil {
		return nil
	}
	return &Address{
		City:        s.City,
		Country:     s.Country,
		CountryCode: s.CountryCode,
		PostalCode:  s.PostalCode,
		State:       s.State,
		StateCode:   s.StateCode,
		Street:      s.Street,
	}
}

// UnMarshalOpsAddress converts a first class object to swagger
func UnMarshalOpsAddress(s *ops_models.Address) *Address {
	if s == nil {
		return nil
	}
	return &Address{
		City:        s.City,
		Country:     s.Country,
		CountryCode: s.CountryCode,
		PostalCode:  s.PostalCode,
		State:       s.State,
		StateCode:   s.StateCode,
		Street:      s.Street,
	}
}
