package entities

import (
	"database/sql/driver"
	"encoding/json"
)

type DeliveryAddressLog struct {
	BaseUuidEntity
	CartID               string
	Address              AddressJson
	RecipientName        string
	RecipientPhoneNumber string
	Version              int64
	Deactivate           bool
}

/*--------------------------------------------------*/

type AddressJson struct {
	Address1          string           `json:"address1"`
	Address2          string           `json:"address2"`
	PostalCode        string           `json:"postalCode"`
	UnitNumber        string           `json:"unitNumber"`
	SubLevelLocations []SubLocationLog `json:"subLevelLocations"`
}

type SubLocationLog struct {
	ID                int64
	InternationalName string
	LocalizedName     string
	ParentID          int64
}

func (v AddressJson) Value() (driver.Value, error) {
	return json.Marshal(&v)
}

func (v *AddressJson) Scan(value interface{}) error {
	return jsonScan(value, v, func() {
		*v = AddressJson{}
	})
}

/*--------------------------------------------------*/
type GetDeliveryAddressLogsParams struct {
	CartID  string
	SortBy  SortBy
	OrderBy OrderBy
}

const SortByVersion SortBy = "version"
